1
저는 파이썬에서 상당히 새롭습니다. 큰 파일을 구문 분석 중이며 특히 입력 된 ID가 파일 헤더에있는 경우 다른 입력이 올바른지 확인하고 싶습니다. 나는 다음과 같은 코드를 실행하면 , 나는이 오류 메시지가 :내 Python 코드의 AttributeError
AttributeError : 'STR'개체가 어떤 속성 'readlines도'
filename = str(raw_input('enter filename: '))
try:
with open(filename, 'rU'): pass
except IOError:
print 'The file does not exist'
sys.exit(0)
def findID(w):
return re.compile(r'\b({0})\b'.format(w), flags=re.IGNORECASE).search
while True:
ID = (raw_input("Enter ID: ")).upper()
IDheader = ID + ".NA"
with open(filename, 'rU') as f:
first_line = f.readline()
if findID(IDheader)(first_line):
print "you entered ",ID
break
else:
pass
print "ID not in this file."`
for line in filename.readlines():
Line = line.split()
if...
당신에게
감사합니다. – Thierry