Python Forum

Full Version: Accessing Files In A Folder
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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