How Python Modules Work

I was wondering how Python modules work? Let's say I want my Python program to create some custom modules for it, where would I put them in relation to the main .py file? (And how would I download them if I didn't use the usual way)

+7
source share
1 answer

If the module is specific to your program, you can put it in the same directory as the main script. From the doc:

When a module named spam imported, the interpreter searches for a file named spam.py in the directory containing the script input, and then in the list of directories specified by the PYTHONPATH environment variable.

I would recommend you read the tutorial on on modules . It is quite short and contains a lot of useful information.

+6
source

All Articles