I am writing a long code that uses many constants, file names, flags, etc. I want to organize all of them neatly in a separate text file named parameters.py and hopefully call them as
import parameters as p
print(p.Constants.speed_of_light)
print(p.Constants.mass_of_sun)
print(p.Constants.hour2seconds)
print(p.Flags.make_plot)
print(p.Flags.save_results)
print(p.Flags.print_results)
print(p.File_names.results)
print(p.File_names.backup)
print(p.File_names.diagnostic)
I expect the output of above to be something like:
3e8
2e30
3600
True
False
True
'file1.txt'
'file2.txt'
'file3.txt'
I am still a beginner at Python so I am not sure how to achieve it. Any help is appreciated!
So, parameters.py should look like
class Constants:
speed_of_light = 3e8
class Flags:
make_plot = True
class File_names:
results = 'file1.txt'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With