简体   繁体   中英

Error while writing ini-file as config (integer required)

i want to use a ini-file as a config file. On programmstart i read the ini-file and while the programm runs i will change values (eg the date) in the file. Here is the Code where i read the ini-file:

inifile = r"C:\Users\A52113242\Desktop\PROJEKTE\[INPROGRESS] AUSWERTUNG COIN + HVL\_tool\cfg\cfg.ini"

config = configparser.SafeConfigParser()
config.read(inifile)

date_hvl = config.get('date', 'date_hvl')
date_coin = config.get('date', 'date_coin')
set_date = time.strftime("%d.%m.20%y")

Here is the function where i want to change the value of "date":

def coin_daten_erstellen():
config.set('date', 'date_coin', set_date)
config.write(sys.stdout)
with open(inifile,'w') as configfile:
    config.write(configfile)

And here is the Error i get:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\A52113242\AppData\Local\Downloaded Apps\Winpython\python-3.4.3\lib\tkinter\__init__.py", line 1533, in __call__
    return self.func(*args)
  File "C:\Users\A52113242\Desktop\PROJEKTE\[INPROGRESS] AUSWERTUNG COIN + HVL\_tool\tool.py", line 179, in coin_daten_erstellen
    with open(inifile,'w') as configfile:
TypeError: an integer is required (got type str)

What am i doing wrong? I dont understand the TypeError why there is an integer needed. Additionally here the ini-file-structure:

[date]
date_coin = 10.07.2017
date_hvl = 10.07.2017

Thank You for the help.

The message suggests it's reading the "+" in your directory like an addition , not a part of the directory.

Maybe shall you retry with no change in code but use a path with no SPACE and no "+" in it ?

example: r"C:\\Users\\A52113242\\Desktop\\PROJEKTE\\INPROGRESS_AUSWERTUNG_COIN_HVL_tool\\cfg\\cfg.ini"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM