Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Accessing Files In A Folder
#1
So I'm working on a program that refers to a lot of data. I store each archive in a separate python file. Each file has a single function: giveArchive() that returns all of its data. So to access any archive, I use:

import fileName
return fileName.giveArchive()

I'm looking to streamline this process a little bit. I want to store all of these files in a folder, and automatically import all of them. I'm trying to just do:

import folderName

which python doesn't seem to have a problem with, but I can't seem to use any of the functions to return archives. How should I go about this?

Using python 3.4.6 btw
Reply
#2
Let me say this is really poor design. You should separate data from logic. Keep data in a database or a simple file (e.g. csv, json, hdf5, etc.) - the choice will depend on type and complexity of data.
What if you need to make changes or add functionality - now you will need to edit every single file.

If you insist on keeping your way - you need to make it a package. Check the documentation
Also a nice post with examples from @snippsat in a similar thread
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Compare folder A and subfolder B and display files that are in folder A but not in su Melcu54 3 465 Jan-05-2024, 05:16 PM
Last Post: Pedroski55
  Rename files in a folder named using windows explorer hitoxman 3 692 Aug-02-2023, 04:08 PM
Last Post: deanhystad
  Rename all files in a folder hitoxman 9 1,384 Jun-30-2023, 12:19 AM
Last Post: Pedroski55
  How to loop through all excel files and sheets in folder jadelola 1 4,329 Dec-01-2022, 06:12 PM
Last Post: deanhystad
  python gzip all files from a folder mg24 3 3,808 Oct-28-2022, 03:59 PM
Last Post: mg24
  delete all files and subdirectory from a main folder mg24 7 1,526 Oct-28-2022, 07:55 AM
Last Post: ibreeden
  Merge all json files in folder after filtering deneme2 10 2,253 Sep-18-2022, 10:32 AM
Last Post: deneme2
  Compare filename with folder name and copy matching files into a particular folder shantanu97 2 4,390 Dec-18-2021, 09:32 PM
Last Post: Larz60+
  pyspark creating temp files in /tmp folder aliyesami 1 4,818 Oct-16-2021, 05:15 PM
Last Post: aliyesami
  Move file from one folder to another folder with timestamp added end of file shantanu97 0 2,433 Mar-22-2021, 10:59 AM
Last Post: shantanu97

Forum Jump:

User Panel Messages

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