这是我的配置文件:
[account1]
username = user1
password = pwd1
[account2]
username = user2
password = pwd2
[account3]
username = user3
password = pwd3
这是我需要做的:
读取confile文件,提取用户名和密码,并将其作为参数传递给另一个脚本。 我想提取这些值并将它们即时传递给第二个脚本。 我不想在两者之间建立另一个字典。
这是我的代码:
#!/usr/bin/python
import ConfigParser
conf = ConfigParser.RawConfigParser()
conf.read('credentials.cfg')
for each_account in conf.sections():
USER = conf.get(each_account, "username")
PASSWORD = conf.get(each_account, "password")
process(USER, PASSWORD)
输出:它仅使用user3和pwd3调用该过程一次。为什么其他两个凭据没有通过?
答案 0 :(得分:0)
您不想处理每个用户名和密码吗?
#!/usr/bin/python
import ConfigParser
conf = ConfigParser.RawConfigParser()
conf.read('credentials.cfg')
for each_account in conf.sections():
USER = conf.get(each_account, "username")
PASSWORD = conf.get(each_account, "password")
process(USER, PASSWORD)