Python Forum

Full Version: Where to place files for import and text files
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello, I am a brand new python programmer and for some reason can not find the answer to this question so I am posting here. Where do I put my .py files for easy importing. Also where would I place .txt files for file io? Would they all go next to my python.exe or what?
You can put the .py files wherever you want. Just add the path to the PYTHONPATH environment variable. The same is for io. Use the full path or relative one as you do it when you are doing file operations in the cmd
I figured I could do that, but where should I put the files so I don't need to bother with paths? like for instance I could open python and just type import "" from "" without needing to specify the path. Would it just be in the same directory? Like say python.exe is in a folder called hello. If I put the files in the same folder, would it be able to import and do file io without specifying a path?
You can keep them in the same directory, or directory tree (if a proper __init__.py file is present see: http://mikegrouchy.com/blog/2012/05/be-p...t__py.html)
then you program will fine the imports.

It's much better (and neater) to keep text and other data, including images in there own sub-directories