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
  Open files in an existing window instead of new Kostov 2 239 Apr-13-2024, 07:22 AM
Last Post: Kostov
  Using zipfile module - finding folders not files darter1010 2 237 Apr-06-2024, 07:22 AM
Last Post: Pedroski55
  Is it possible to extract 1 or 2 bits of data from MS project files? cubangt 8 1,005 Feb-16-2024, 12:02 AM
Last Post: deanhystad
  File loop curiously skipping files - FIXED mbk34 10 777 Feb-10-2024, 07:08 AM
Last Post: buran
  Copy Paste excel files based on the first letters of the file name Viento 2 409 Feb-07-2024, 12:24 PM
Last Post: Viento
  Class test : good way to split methods into several files paul18fr 4 466 Jan-30-2024, 11:46 AM
Last Post: Pedroski55
  uploading files from a ubuntu local directory to Minio storage container dchilambo 0 439 Dec-22-2023, 07:17 AM
Last Post: dchilambo
  Upload Files to Azure Storage Container phillyfa 6 665 Dec-22-2023, 06:11 AM
Last Post: Pedroski55
  merge all xlsb files into csv mg24 0 327 Nov-13-2023, 08:25 AM
Last Post: mg24
  Newbie question about switching between files - Python/Pycharm Busby222 3 590 Oct-15-2023, 03:16 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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