问题
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)
回答1:
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
spamis 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.
来源:https://stackoverflow.com/questions/7803493/how-do-python-modules-work