Asher Silverglade
Asher Silverglade

Reputation: 53

Importing a whole folder of python files

In the current python program I'm working on, I need to access a lot of stored data. I store it in the form of a bunch of dictionaries, each in their own file. Each file has a single command: giveArchive(). So to access one of the files, I use:

import fileName
return fileName.giveArchive()

And this has worked well so far, but as the number of files I need grows, I want to streamline this a little bit. I'd like to store all of these files in the same folder, and that folder in the same directory as my main file. Is there some way I can import every file in a folder? And if I do, how can I use 'giveArchive()' from specific files in it?

Upvotes: 4

Views: 104

Answers (1)

Reedinationer
Reedinationer

Reputation: 5774

You can do something like:

from folder.subfolder.deepersubfolder import filename
return filename.giveArchive()

this assumes folder can be accessed from the directory your script is running in

Upvotes: 0

Related Questions