封装读取配置文件的方法是否可以这样写
来源:2-20 重构封装读取配置文件方法

精慕门1029620
2022-02-18
封装读取配置文件的方法是否可以这样写
import configparser
class ReadIni():
def __init__(self,file,node,key):
self.file = file
self.node = node
self.key = key
def get_value(self):
cf = configparser.ConfigParser()
cf.read(self.file,encoding='utf-8')
value = cf.get(self.node,self.key)
return value
readini = ReadIni('F:\selenium_test\config.ini','Element','user_num')
print(readini.get_value())
写回答
1回答
-
Mushishi
2022-02-21
可以的。随便怎么封装。这个只是思路
00
相似问题