老师,代码报错TypeError: 'NoneType' object is not iterable
来源:2-20 重构封装读取配置文件方法

weixin_慕哥2269558
2021-06-16
import configparser
class readini(object):
def init(self,node=None):
if node == None:
self.node = "element"
else:
self.node = node
self.cf = self.load_ini(filename)
def load_ini(self,filename):
self.cf = configparser.ConfigParser()
self.cf.read(filename)
return self.cf
def get_value(self,node,key):
data = self.cf.get(node,key)
return data
if name == ‘main’:
read_ini = readini()
read_ini.load_ini(“D:/python/Tools/config/localelement.ini”)
print(read_ini.get_value(‘elements’,‘username’)
报错
File “D:/python/raed——ini.py”, line 13, in load_ini
self.cf.read(filename)
File “D:\python\lib\configparser.py”, line 693, in read
for filename in filenames:
TypeError: ‘NoneType’ object is not iterable
ini文件
[elements]
username=id>register-btn
1回答
-
Mushishi
2021-06-16
TypeError: 'NoneType' object is not iterable
说明你这个对象是不可迭代的。你一个空怎么迭代呢?你filenames 是kong的
你filename在哪里?你构造函数里面没传递。
self.cf = self.load_ini(filename)
022021-06-18
相似问题