簡體   English   中英

configparser.NoSectionError:沒有部分:'general_info'

[英]configparser.NoSectionError: No section: 'general_info'

我從 .py 文件創建了一個 exe 文件,在該代碼中,我從 config.ini 文件中檢索了一個值。 當我將 .py 文件轉換為 .exe 文件並雙擊它時,它工作正常。 但是當創建任務計划程序以在 windows 啟動時運行該 exe 文件時,我收到錯誤消息:

configparser.NoSectionError: No section: 'general_info'

注意該部分已經存在並且如上所述,當通過雙擊運行 exe 文件時,它工作正常

代碼:

import time
import os
import subprocess
from configparser import ConfigParser, RawConfigParser
 
thisfolder = os.getcwd()  
initfile = os.path.join(thisfolder, 'config.ini').replace('\\', '\\\\')
 
config = RawConfigParser()
 
config.read(initfile)
check_every_minutes = int(config.get('general_info', 'check_every_minutes').strip()) * 60

配置文件:

[general_info]
check_every_minutes = 1

有人有想法嗎?

問題通過將 config.ini 文件放在 C:/Windows 中解決,因為任務調度程序以某種方式從 C:/Windows 中的相對路徑讀取

暫無
暫無

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

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