Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do Python modules work

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)

like image 600
Arcticfoxx Avatar asked Oct 18 '11 06:10

Arcticfoxx


1 Answers

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.

like image 140
NPE Avatar answered Oct 28 '22 16:10

NPE