新建一个env.ini文件:
[apidemo01]
URL=192.168.2.4:9999
[cdd]
password=123456
使用pyhon 读取ini文件中想要获取的内容:
class TestCase:
def test_01(self):
# configparser 文件对象
config = configparser.ConfigParser()
# 读取那个文件
config.read("env.ini",encoding="utf-8")
url = config.get("cdd", "password")
print(url)
该文章展示了一个Python程序如何使用configparser模块从env.ini文件中读取特定值,例如[cdd]部分的password。首先创建ConfigParser对象,然后读取文件并获取相应section的值。
1万+

被折叠的 条评论
为什么被折叠?



