Problème Ajout Elément dans une section avec ConfigParser
Bonjour à tous,
J'ai implémenté un code pour ajouter des éléments dans une section.
voilà le code python:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
# -*- coding: utf-8 -*-
from ConfigParser import RawConfigParser
import sys
class EditInitMysql:
def AddElementIniMysql(self,Path, SectionName,ElementName, ElementValue):
config = RawConfigParser()
config.set(SectionName, ElementName,ElementValue)
# Writing our configuration file to 'example.cfg'
with open(Path, 'wb') as configfile:
config.write(configfile)
config.close()
if __name__=="__main__":
edmysql=EditInitMysql()
#edmysql.AddElementIniMysql(sys.argv[1],sys.argv[2],sys.argv[3],sys.argv[4])
edmysql.AddElementIniMysql('C:/Users/OWIOWI/Desktop/test python/test/my-test.ini', 'client', 'port', 2205) |
Quant je lance le code sur un fichier voilà ce que j'ai ey comme erreur:
Code:
1 2 3 4 5
|
config.set(SectionName, ElementName,ElementValue)
File "C:\Python27\lib\ConfigParser.py", line 396, in set
raise NoSectionError(section)
ConfigParser.NoSectionError: No section: 'client' |
Avez-vous une idée sur ce problème svp !
Merci beaucoup d'avance pour vos retours !