09/07/12 13:10:28
>>387
こんな感じです
#ファイルの2行目からの文字列を3行ずつリストの1要素にまとめて扱いたい
fhnd = open('spam.txt','r')
lines = []
add_up = []
line_start = 2
line_end = 5
for temp in fhnd:
lines.append(temp)
for temp in lines:
if (line_start > line_max) or (line_end > line_max):
break
add_up.append(lines[line_start] + lines[line_start+1] + lines[line_end-1]) #←化けない
# add_up.append(lines[line_start:line_end]) #←上の代わりに実行すると化ける
print str(add_up[0]) + str(add_up[1]) + str(add_up[2])#←上のfor文内のうち上の行を実行なら化けない
print str(add_up[0:3])#←上のfor文内のいずれでも化ける