我有一个类来包装程序的配置内容。 但是当我尝试在ipython中测试我时:
c = Config(test.cfg)
我收到错误:
"TypeError: read() missing 1 required positional argument: 'filenames'
"
但是我的pylint在我的emacs中抛出了这个错误:
"No value for argument 'filenames' in unbound method call"
我认为错误以及错误是其上方错误的原因。 但我不知道为什么。 我认为该方法是调用绑定的,因为我使用self作为参考,但我不是shure而且我不明白为什么它不接受cfg作为参数。
这是我的班级:
from configparser import ConfigParser
class Config:
"""Wrapper around config files
Args:
cfg: main config file
"""
def __init__(self, cfg=None):
self.cfg = []
self.cfgraw = cfg
self.scfgs = []
self.scfgs_raw = []
if not cfg is None:
self.add(typ="main", cfg=cfg)
def add(self, typ, cfg):
"""add config file
Args:
typ: type of file main or sub
Returns:
none
"""
if typ is not "main" and cfg is None:
raise ValueError('no file provied and type not main')
if typ is "sub":
for index in range(len(self.scfgs)):
self.scfgs[index] = ConfigParser
self.scfgs[index].read(cfg)
if typ is "main":
self.cfg = ConfigParser
self.cfg.read(cfg)
def write(self, typ=None, index=None):
"""write changes made
Args:
typ: type of target file
index: if type is sub add index to write selected file
Returns:
none
"""
if typ is "main":
self.cfg.write(self.cfgraw)
if typ is "sub":
if index is None:
for item in range(len(self.scfgs)):
self.scfgs[item].write(self.scfgs_raw[item])
else:
self.scfgs[item].write(self.scfgs_raw[item])
答案 0 :(得分:9)
您没有在ConfigParser
之前的行上正确初始化read
- 您错过了()
来实际创建实例。
尝试:
if typ is "main":
self.cfg = ConfigParser()
self.cfg.read(cfg)
答案 1 :(得分:5)
将ConfigParser
或self.scfgs
属性分配给self.cfg
时,您不会实例化read
;所以当你在它上面调用self.cfg = ConfigParser()
时,你通过类调用一个未绑定的方法,而不是实例上的方法。
应该是:
$("#searchInput").keyup(function() {
var rows = $(".rows").find('tr').hide();
var data = this.value.split("/");
$.each(data, function(i, v) {
rows.filter(":Contains('" + v + "')").show();
});
});
jQuery.expr[":"].Contains = jQuery.expr.createPseudo(function(arg) {
return function(elem) {
return jQuery(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0;
};
});
等