Accessing Files In A Folder - 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: Accessing Files In A Folder (/thread-16126.html) |
Accessing Files In A Folder - asilverg - Feb-14-2019 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 RE: Accessing Files In A Folder - buran - Feb-15-2019 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 |