Bonjour,
Je débute en python j'ai besoin de passer 2 valeurs paramètres dans un appel de programme d'un logiciel.
J'ai créé un fichier batch.cfg de ce type:
J'y ai associé le code suivant:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 [LOGIN] User=mon_user Passw=monpassw
À l’exécution j'ai l'erreur suivante :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 #!/usr/bin/env python # -*- Encoding: utf-8 -*- import os import configparser config = configparser.ConfigParser() config.read('batch.cfg') Parm1=config.get('LOGIN','User') Parm2=config.get('LOGIN','Passw') # run batch 1 os.chdir("E:\toto\") os.system("toto.exe Parm1 Parm2 1") # --> le 1 étant le N° du batch dans le logiciel
Pouvez-vous m'aider, je ne comprends pas pourquoi ma section n'est pas reconnue.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 File "C:\Program Files (x86)\Python35-32\lib\configparser.py", line 1135, in _unify_values sectiondict = self._sections[section] KeyError: 'LOGIN' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "E:\SHARE\TOOLS\INDUS\BATCH_LAUNCHERS\BATCH_1.py", line 7, in <module> Parm1=config.get('LOGIN','User') File "C:\Program Files (x86)\Python35-32\lib\configparser.py", line 778, in get d = self._unify_values(section, vars) File "C:\Program Files (x86)\Python35-32\lib\configparser.py", line 1138, in _unify_values raise NoSectionError(section) configparser.NoSectionError: No section: 'LOGIN'
Merci
Partager