Python Forum
Where to place files for import and text files
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Where to place files for import and text files
#1
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?
Reply
#2
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
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
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?
Reply
#4
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Correct/proper way to create save files snakes 0 460 Mar-11-2025, 06:58 PM
Last Post: snakes
  Merge htm files with shutil library (TypeError: 'module' object is not callable) Melcu54 7 3,340 Mar-09-2025, 04:25 PM
Last Post: Pedroski55
  how to download large files faster? kucingkembar 3 815 Feb-20-2025, 06:57 PM
Last Post: snippsat
  Inserting Python Buttons into KV Files edand19941 3 501 Feb-19-2025, 07:44 PM
Last Post: buran
Question [SOLVED] Right way to open files with different encodings? Winfried 3 4,149 Jan-18-2025, 02:19 PM
Last Post: Winfried
  Applications config files / Best practices aecordoba 2 1,959 Oct-23-2024, 12:56 PM
Last Post: aecordoba
  Compare 2 files for duplicates and save the differences cubangt 2 955 Sep-12-2024, 03:55 PM
Last Post: cubangt
  Convert Xls files into Csv in on premises sharpoint Andrew_andy9642 3 1,020 Aug-30-2024, 06:41 PM
Last Post: deanhystad
  deleting files in program files directory RRADC 6 2,980 Aug-21-2024, 06:11 PM
Last Post: snippsat
  I'm trying to merge 2 .csv files with no joy! Sick_Stigma 3 941 Aug-03-2024, 03:20 PM
Last Post: mariadsouza362

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020