I was wondering how do Python modules work? Say I want to make my Python program some custom modules to package with it, where would I put them in relation to the main .py file?(and how would I load them if not using the usual way)
If the module is specific to your program, you can put into the same directory as the main script. From the documentation:
When a module named
spam
is imported, the interpreter searches for a file named spam.py in the directory containing the input script and then in the list of directories specified by the environment variable PYTHONPATH.
I would recommend that you read the entire tutorial on modules. It's pretty short and has a lot of useful info.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With