我正在尝试使用配置解析器读取文件路径,然后从该文件读取
>>> cfg_file = './crawler.config'
>>> config = SafeConfigParser()
>>> config.read(cfg_file)
['./crawler.config']
>>> f = config.get('default', 'sites_file')
>>> with open(f) as fp:
... print fp.read()
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IOError: [Errno 2] No such file or directory: u'"/home/avi/src/typo.csv"'
>>>
我认为Unicode存在问题。我无法找到解决方案。如果我直接将文件名作为字符串传递它可以正常工作。任何帮助解决这个问题都将受到赞赏。
答案 0 :(得分:0)
(function($) {
var dom;
/* Cache the necessary DOM nodes for this module. */
var cacheDOM = function() {
dom = {};
dom.document = $(document);
dom.template = dom.document.find('#tmplt');
dom.inputModal = dom.template.find('.modal__input'); // that's empty
dom.formCircle = dom.template.find('.modal__form--invalid'); // that's empty
};
/* Change the image based on the validity of the input's value. */
var inputModalValid = function() {
var
/* Cache the child nodes of the template's own DOM. */
nodes = $(dom.template.prop('content').children),
/* Cache the input and the image. */
$input = nodes.find('.modal__input'),
$check = nodes.find('.modal__form--invalid');
/* Set an event listener for the 'keyup' event. */
$input.on('keyup', function() {
/* Check the validity of the input. */
if (this.checkValidity() == true) {
$check.attr("src", 'src/images/checkmark-circle.png');
} else {
$check.attr("src", "src/images/circle-form.png");
}
});
}
/* Initialize the module. */
cacheDOM();
inputModalValid();
}(jQuery));
可能是&#34; /home/avi/src/typo.csv"
不存在
f = config.get('default', 'sites_file')
您正在尝试阅读不存在的文件
答案 1 :(得分:0)
尝试将配置中&#39; sites_file&#39; 的值从/home/avi/src/typo.csv
更改为"/home/avi/src/typo.csv"
或强>
在打开文件之前替换引号。
例如:
with open(f.replace('"', '')) as fp:
print fp.read()