0

I can see a similar question has been asked before but I couldn't understand the answers given, they related to a specific python configuration file.

I have a large number of python (and shell) scripts which read configuration information such as paths, database settings, etc from a simply formatted configuration file, which I can easily parse with ConfigParser when using Python (and also easily use for the shell scripts too), e.g.:

[paths]
mypath = /another/path/
fileExt = .zip

The path to the config file was hardwired, both in the main script but also in a couple of modules where it is required. As expected, it is a pain as I need a couple of different config files for testing, for different systems, etc, and I'd prefer just to pass the relevant one as an input to the main script instead but this doesn't really work either.

Where I ran into the issue, I have:

  • Main script, A, that calls functions from a locally imported script, B.
  • In B, before the functions are defined, there is a function call to an imported function from another file, C.
  • A and C never talk.

I could pass the config file to the functions as a variable (seems messy) but I still can't get it to the file I've called "C" above.

emmalg
  • 346
  • 2
  • 12

1 Answers1

0

Although the question posed was slightly different, I have found that the answer from: Creating a class with all the elements specified in a file using ConfigParser works really well. Although I still can't pass the name of the file in, I now only have it hardcoded in one place.

Community
  • 1
  • 1
emmalg
  • 346
  • 2
  • 12