Python Forum
saving my *.py files - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: saving my *.py files (/thread-3748.html)



saving my *.py files - tozqo - Jun-20-2017

So, (possibly off topic) if I have been saving my *.py files to anywhere other than where I installed my Python, then I won't be able to import them to the module I am working on?


RE: saving my *.py files - snippsat - Jun-20-2017

Can use site module.
Make a file sitecustomize.py in site-packages folder.
import site
site.addsitedir('C:/py_files')
Now will py_files folder be permanently added to sys.path

For one session can use append to sys.path.append
>>> import sys
>>> sys.path.append('C:/foo')
>>> sys.path
['',
 ... all other dir in sys.path
 'C:\\foo',
 'C:\\py_files',
 ]



RE: saving my *.py files - Kebap - Jun-21-2017

(Jun-20-2017, 10:25 AM)tozqo Wrote: be able to import them to the module I am working on?

Do you want to import these files permanently for all kind of future projects? Or is your project just split into multiple files, that you want to combine for your module now?

While metulburr answered the first case, in the second case you can also just easily put your files in the same folder as the new file you execute, or in a sub-folder for easier access as a package like this: from sub_folder import module or even from sub_folder.module import my_function

See here for more details: https://docs.python.org/3.3/tutorial/modules.html#packages

You are definitely not expected to save all your *.py files to the python install folder, no Shocked