을 부여하고 벽에 붙어있어삽입 문자열은 내가 문제가 일하고 파일 객체
나는 텍스트 파일의 (잠재적으로 큰) 세트가, 나는 순서를 적용해야 필터 및 변환을 가져 와서 다른 위치로 내 보냅니다.
그래서 대략def apply_filter_transformer(basepath = None, newpath = None, fts= None):
#because all the raw studies in basepath should not be modified, so I first cp all to newpath
for i in listdir(basepath):
file(path.join(newpath, i), "wb").writelines(file(path.join(basepath, i)).readlines())
for i in listdir(newpath):
fileobj = open(path.join(newpath, i), "r+")
for fcn in fts:
fileobj = fcn(fileobj)
if fileobj is not None:
fileobj.writelines(fileobj.readlines())
try:
fileobj.close()
except:
print i, "at", fcn
pass
def main():
apply_filter_transformer(path.join(pardir, pardir, "studies"),
path.abspath(path.join(pardir, pardir, "filtered_studies")),
[
#transformer_addMemo,
filter_executable,
transformer_identity,
filter_identity,
])
을 가지고 apply_filter_transformer에서 FTS는 파이썬 파일 객체를 받아 파이썬 파일 객체를 반환 기능의 목록입니다. 내가 들어간 문제는 문자열을 텍스트 객체에 삽입하려고 할 때 정보가없는 오류가 발생하고 아침 내내 막혔다는 것입니다.
def transformer_addMemo(fileobj):
STYLUSMEMO =r"""hellow world"""
study = fileobj.read()
location = re.search(r"</BasicOptions>", study)
print fileobj.name
print fileobj.mode
fileobj.seek(0)
fileobj.write(study[:location.end()] + STYLUSMEMO + study[location.end():])
return fileobj
누군가가 나에게 오류에 대한 자세한 정보를 줄 수 있다면이 나에게
Traceback (most recent call last):
File "E:\mypy\reg_test\src\preprocessor\preprocessor.py", line 292, in <module>
main()
File "E:\mypy\reg_test\src\preprocessor\preprocessor.py", line 288, in main
filter_identity,
File "E:\mypy\reg_test\src\preprocessor\preprocessor.py", line 276, in apply_filter_transformer
fileobj.writelines(fileobj.readlines())
IOError: [Errno 0] Error
을 제공합니다, 나는 매우 매우 감사하겠습니다.
서식을 수정하십시오. –