그래서 파일에서 텍스트를 가져 와서 사전으로 이동 한 다음 처리하는 코드를 작성하려고합니다. 이 오류가 계속 :사전에 파일을 실행할 수 없습니다.
File "C:\Users\Oghosa\Assignment2.py", line 12, in <module>
builtins.IndexError: string index out of range
여기 내 프로그램입니다 :
endofprogram = False
dic = {}
try:
filename = input("Please Enter the Filename:")
infile = open(filename, 'r')
except IOError:
print("Error Reading File! Program ends here!")
endofprogram = True
if endofprogram == False:
for line in infile:
line = line.strip("\n")
if (line != " ") and (line[0] != "#"):
item = line.split(":")
print(items)
dic["Animal id"] = item[0]
dic["Date"] = item[1]
dic["Station"] = item[2]
print(dic)
하시기 바랍니다 내 실수를 지적 누군가의 도움이 수 있습니까?
다음은 샘플 입력 텍스트는 다음과 같습니다
#Comments
a01:01-24-2011:s1
a03:01-24-2011:s2
<blank line>
<blank line>
a02:01-24-2011:s2
a03:02-02-2011:s2
a03:03-02-2011:s1
a02:04-19-2011:s2
<blank line>
#comments
a01:05-14-2011:s2
a02:06-11-2011:s2
a03:07-12-2011:s1
a01:08-19-2011:s1
a03:09-19-2011:s1
a03:10-19-2011:s2
a03:11-19-2011:s1
a03:12-19-2011:s2
당신은 우리에게 입력 파일 샘플을 줄 수 있습니까? – Christian
@Christian 여기에 animallog.txt라고하는 사람이 있습니다. – user2767528
댓글을 달거나 게시물을 편집해서 올려 놓지 마십시오. 포맷이 올바른지 확인하십시오. – Christian