Python配置分析器.noSection

2024-10-01 11:30:44 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我的代码:

import ConfigParser
configuration = ConfigParser.ConfigParser()
configuration.read('timesheetconfig.ini')
username = configuration.get('internal','username')
password = configuration.get('internal','password')
url  = configuration.get('internal','url')
browser = configuration.get('internal','browser') 

我也试过替换: 配置.读取('C:\SikuliConfig\时间表配置.ini')

这是时间表配置.ini在

^{pr2}$

你知道我为什么会这样吗???在

[error] script [ ScriptName ] stopped with error in line 4
[error] ConfigParser.NoSectionError ( No section: 'internal' )

Tags: 代码importbrowserurlreadgetusernameerror
1条回答
网友
1楼 · 发布于 2024-10-01 11:30:44

因为某种原因配置.读取无法打开同一文件夹中的文件。我用Cygwin在Python中测试了相同的代码,它工作得很好,因此它与Sikuli有关。在

我通过在导入后添加ConfigParser来解决此问题:

import ConfigParser
# get the directory containing your running .sikuli
myPath = os.path.dirname(getBundlePath())
if not myPath in sys.path: sys.path.append(myPath)

那么

^{pr2}$

在Sikuli文档中搜索"Another example: Importing from the same directory"

相关问题 更多 >