Python config file parsen



  • Hallo, ich versuche gerade zu einem Programm eine config -file zu schreiben, welche ich dann bequem einlesen kann.
    Optisch sollte diese aber auch was hermachen. Bis jetzt sieht eine solche Datei in etwa so aus:

    ## This is the CREATE_JOBS config file
    
    ## General Options
    -log:           <file>          # Copy output to logfile.
    -ode:           <name>          # Implementation variant.
    -solver:        <name>          # Name of embedded RK method.
    -t0:            <double>        # Start time.
    -H:             <double>        # Integration interval.
    -bf:            <double>        # Maximum error allowed in integration.
    -accbf:         <double>        # Maximum error allowed in accuracy computation.
    -time                           # Activate time measurement.
    -stat                           # Activate statistics.
    -ei                             # Show error index.
    -acc                            # Activate accuracy computation.
    -cmp                            # Compare with reference solution.
    -perfctr:       <event>         # Activate evaluation of hardware counters.
    -steps:         <int>           # Number of steps to measure.
    -warmup-steps:  <int>           # Number of warmup steps before measurement.
    -walltime:      <double>        # Walltime limit for measured steps in s.
    -table:         <file>          # Append statistics etc. to table.
    -dump:          <file>          # Dump solution vector to file.
    

    Leider scheitere ich bisher daran diese Datei mit pythons configparser einzulesen.

    configparser.ParsingError: File contains parsing errors: create_jobs.cfg
    [line 18]: '-time \t\t \t# Activate time measurement.\n'
    [line 19]: '-stat \t \t# Activate statistics.\n'
    [line 20]: '-ei \t\t# Show error index.\n'
    [line 21]: '-acc \t\t# Activate accuracy computation.\n'
    [line 22]: '-cmp \t\t# Compare with reference solution.\n'

    Ich weiß leider nicht einmal was für Probleme er hat... ich möchte aber auf keinen Fall den Stil der C-Datei ändern, da ich glaube dass dieser sowohl gut aussieht als auch zweckmäßig ist.

    Dennoch brauche ich noch einen Parser? Gibts da noch Optionen die ich nicht kenne? (Verwende bisher nur RawConfigParser()) oder muss ich doch selbst etwas schreiben?



  • sry das problem ist doch ziemlich klar,
    nur möchte ich nicht

    -time true

    oder ähnliches reinschreiben, falls kein schlüssel-wert paar vorhanden ist so soll er einfach den schlüssel nehmen und sich eine 1 denken. Kann man das einfach machen ohne erst von Configparser abzuleiten?



  • kann geschlossen werden, hab die datei angepasst.


Anmelden zum Antworten