2017-08-09 56 views
0

我想用一個ini文件作爲配置文件。上programmstart我讀ini文件並且在運行PROGRAMM我會改變的值(例如日期)的文件中。這裏是我讀的ini文件中的代碼:錯誤而寫的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 

謝謝你的幫助。

+0

你顯然已經覆蓋內置'的open()'用別的東西的標準,也許通過從某個模塊導入不同的'open'。 (如果你使用'從X導入*這種錯誤是特別容易')。如果你不能找出哪裏不好'open'從,'打印來(開)'或'幫助(打開)'可能給一個線索。 – jasonharper

+0

與打印(開),我得到:<內置函數open> – Damian

回答

0

的消息表明,它的閱讀了「+」在目錄像此外,該目錄中沒有的部分。

也許你應當重新用代碼中沒有變化,但使用的路徑,在它沒有空間,沒有「+」?

例如: R 「C:\用戶\ A52113242 \桌面\ PROJEKTE \ INPROGRESS_AUSWERTUNG_COIN_HVL_tool \ CFG \ cfg.ini」

+0

是didnt解決我的問題。我得到相同的錯誤。 – Damian