ことを確認してください
a) 各行の長さは 4 列です
b) プログラムの最後に改行 ('\n') があっても失敗しないようにする
def ask_for_filename():
filename=raw_input("Please enter file name: ")
return filename
def read_data(filename):
with open(filename) as f:
data = f.readlines()
i = 0
for line in data:
lineContains = line.split('\t')
lineLength = len(lineContains) #calculate elements
i = i+1
if lineLength < 3 and i < len(data):
print "File is invalid format."
f.close()
return data
コードのこの部分が機能しないため、問題のある場所を修正してください。
i = 0
for line in data:
lineContains = line.split('\t')
lineLength = len(lineContains) #calculate elements
i = i+1
if lineLength < 3 and i < len(data):
print "File is invalid format."
サンプル ファイルの内容:
完全なファイル:
AUTHOR(S) YEAR TITLE JOURNAL/CONFERENCE
Accot;Zhai 2001 Scale effects in steering law tasks Proc. ACM CHI
Acredolo 1977 Developmental Changes in the Ability to Coordinate Perspectives of a Large-Scale Space Developmental Psychology
Aginsky;Harris;Rensink;Beusmans 1997 Two strategies for learning a route in a driving simulator Journal of Environmental Psychology
不完全なファイル (前述のコードはこれらの種類のファイル用です):
AUTHOR(S) YEAR TITLE JOURNAL/CONFERENCE
Accot;Zhai 2001 Scale effects in steering law tasks Proc. ACM CHI
Acredolo Developmental Changes in the Ability to Coordinate Perspectives of a Large-Scale Space Developmental Psychology
Aginsky;Harris;Rensink;Beusmans 1997 Two strategies for learning a route in a driving simulator Journal of Environmental Psychology
Agrawala;Beers;Frohlich;Hanrahan;McDowall;Bolas 1997 The two-user responsive workbench: Support for collaboration through individual views of a shared space Proc. ACM SIGGRAPH
Ahmadabadi;Eiji 1996 Cooperation strategy for a group of object lifting robots Proc. of IROS