簡體   English   中英

將ini文件作為配置寫入時出錯(需要整數)

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

我想使用ini文件作為配置文件。 在programmstart上,我讀取了ini文件,並且在programm運行時,我將更改文件中的值(例如日期)。 這是我讀取ini文件的代碼:

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")

這是我要更改“日期”值的函數:

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

這是我得到的錯誤:

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)

我究竟做錯了什么? 我不理解TypeError為什么需要整數。 另外,這里的ini文件結構:

[date]
date_coin = 10.07.2017
date_hvl = 10.07.2017

感謝您的幫助。

該消息表明它正在讀取目錄中的“ +”,就像添加內容一樣,而不是目錄的一部分。

也許您應該重試而無需更改代碼,而是使用沒有SPACE且其中沒有“ +”的路徑?

示例:r“ C:\\ Users \\ A52113242 \\ Desktop \\ PROJEKTE \\ INPROGRESS_AUSWERTUNG_COIN_HVL_tool \\ cfg \\ cfg.ini”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM