파일을 열려고하지만이 오류 얻을 :파이썬 2.5.2 : 아래 스크립트는 재귀 적으로 'pruebaba'폴더 내의 모든 파일을 열어야합니다 재귀
pruebaba
folder1
folder11
test1.php
folder12
test1.php
test2.php
folder2
test1.php
:이 계층 구조가
Traceback (most recent call last):
File "/home/tirengarfio/Desktop/prueba.py", line 8, in f = open(file,'r') IOError: [Errno 21] Is a directory
입니다
스크립트 :
import re,fileinput,os
path="/home/tirengarfio/Desktop/pruebaba"
os.chdir(path)
for file in os.listdir("."):
f = open(file,'r')
data = f.read()
data = re.sub(r'(\s*function\s+.*\s*{\s*)',
r'\1echo "The function starts here."',
data)
f.close()
f = open(file, 'w')
f.write(data)
f.close()
어떤 생각?
... 감사합니다. – espais