ConfigParser 的文件应该是什么格式?

What format should the file for ConfigParser be?

我正在为图书馆设置凭据:https://pypi.python.org/pypi/python-amazon-product-api/

项目文件中相关配置解析器的代码here

我想知道,配置文件变量应该是什么格式?字符串应该插入引号内吗?变量名和等号之间要不要有空格?

这个看起来怎么样?

[Credentials]
access_key=xxxxxxxxxxxxxxxxxxxxx
secret_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
associate_tag=xxxxxxxxxxxx

摘自 documentation

The configuration file consists of sections, led by a [section] header and followed by name: value entries, with continuations in the style of RFC 822 (see section 3.1.1, “LONG HEADER FIELDS”); name=value is also accepted. Note that leading whitespace is removed from values. The optional values can contain format strings which refer to other values in the same section, or values in a special DEFAULT section. Additional defaults can be provided on initialization and retrieval. Lines beginning with '#' or ';' are ignored and may be used to provide comments.

Configuration files may include comments, prefixed by specific characters (# and ;). Comments may appear on their own in an otherwise empty line, or may be entered in lines holding values or section names. In the latter case, they need to be preceded by a whitespace character to be recognized as a comment. (For backwards compatibility, only ; starts an inline comment, while # does not.)

On top of the core functionality, SafeConfigParser supports interpolation. This means values can contain format strings which refer to other values in the same section, or values in a special DEFAULT section. Additional defaults can be provided on initialization.

For example:

[My Section]
foodir: %(dir)s/whatever
dir=frob
long: this value continues
   in the next line

您可以很自由地在设置文件中编写任何您想要的内容。

在您的特定情况下,您只需复制并粘贴您的密钥和标签,ConfigParser 会完成剩下的工作。