Skip to content

Instantly share code, notes, and snippets.

View ides-dev's full-sized avatar
🤍

★ ides !! ides-dev

🤍
View GitHub Profile
@MRobertEvers
MRobertEvers / Python_Import_Other_Directories.md
Created May 6, 2018 19:41
Import Python Files From Another Directory Python 3

Import Python Files From Another Directory

I've come across various ways to include files from other directories in python. At this time, none of my python projects have ever scaled enough to warrant a nice directory structure but I find this information useful to know.

Module Search

The Python Docs 6.1.4 explain nicely what happens when you try to import a module.

When a module named spam is imported, the interpreter first searches for a built-in module with that name. If not found, it then searches for a file named spam.py in a list of directories given by the variable sys.path. sys.path is initialized from these locations:
- The directory containing the input script (or the current directory when no file is specified).
- PYTHONPATH (a list of directory names, with the same syntax as the shell variable PATH).
  • The installation-dependent default.
@EvieePy
EvieePy / error_handler.py
Last active August 14, 2024 17:13
Simple Error Handling for ext.commands - discord.py
"""
If you are not using this inside a cog, add the event decorator e.g:
@bot.event
async def on_command_error(ctx, error)
For examples of cogs see:
https://gist.github.com/EvieePy/d78c061a4798ae81be9825468fe146be
For a list of exceptions:
https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#exceptions