Python Forum
Where to place files for import and text 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: Where to place files for import and text files (/thread-1878.html)



Where to place files for import and text files - hellboy632789 - Feb-01-2017

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?


RE: Where to place files for import and text files - wavic - Feb-01-2017

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


RE: Where to place files for import and text files - hellboy632789 - Feb-01-2017

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?


RE: Where to place files for import and text files - Larz60+ - Feb-01-2017

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-pythonic-__init__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