Closed mikesmic closed 3 years ago
It depends how many there are. If there are 6 or fewer then you can do them as command line parameters. Something like:
import argparse
def get_arguments():
""" Get command-line arguments passed to this file
:return parser: Arguments passed on the command line (argparse.ArgumentParser)
"""
# Set up parser and sub parsers
parser = argparse.ArgumentParser()
parser.add_argument("-f", "--file_path",
help="The file path to process",
default="temp.data")
parser.add_argument("-p", "--num_penguins",
help="The number of penguins being observed.",
default="42")
def main(paramter_dict):
file_path = paramter_dict["file_path"]
number_of_penguins = paramter_dict["num_penguins"]
if __main__():
ARG_PARSER = get_arguments()
# Convert arg parser object to a dictionary
ARGS = vars(ARG_PARSER.parse_args([]))
main(ARGS)`
If there are more than 6 or so this then becomes quite unwieldy and you are better with a config file. In this case I like the .ini config format (just like .cpr files) where section headers are in square brackets and the values beneath are in the key=value style
[Acquisition Surface]
Euler1=0.0
[Fields]
Count=9
Field1=3
You can then read this file nicely into a dictionary like object using the configparser built in module: https://docs.python.org/3/library/configparser.html
@merrygoat do you know I good way to do this? So we could have a separate file to store any default parameters for all the modules. I think a some parameters are hardcoded all over the place currently