0

我尝试创建一个配置文件,我可以在其中存储常量。

每当我尝试使用 ConfigParser 时,都会出现错误

Traceback (most recent call last):
  File "/home/baun/google_appengine/google/appengine/ext/webapp        /__init__.py", line 511, in __call__
    handler.get(*groups)
  File "/home/baun/workspace/octopuscloud/s3/S3.py", line 138, in get
    test = parser.get('bucket', 'bucketname')
  File "/usr/lib/python2.5/ConfigParser.py", line 511, in get
    raise NoSectionError(section)
NoSectionError: No section: 'bucket'

简单的.cfg:

[bucket]
bucketname: 'octopus_storage'

s3.py:

...
from ConfigParser import SafeConfigParser

parser = SafeConfigParser()
parser.read('simple.cfg')

...

# Get values from the config file
test = parser.get('bucket', 'bucketname')
...

我怎样才能解决这个问题?

================================

问题已解决。代码是正确的,但 simple.cfg 位于错误的目录中。

4

1 回答 1

2
[bucket]
bucketname= octopus_storage
于 2010-10-29T09:09:59.230 回答