File をopenして1行ずつ読み込む。file-test-1.txt の複数の行を1行ずつ書き込んでいく。
for line in f:
print line
f2.write(line)
------------------------
file-open.py
------------------------
#!/usr/bin/python
f = open ('file-test-1.txt', 'r')
f2 = open ('file-test-2.txt', 'w')
for line in f:
print line
f2.write(line)
#print ('cheers')
#print f.read()
#print ('cheers')
#print f.readline()
f2.write('IAP')
f.close()
f2.close()
------------------------
file-test-1.txt
------------------------
kurokawa-no-MacBook-Air:Linux taka$ more file-test-1.txt
a,line-1,c
b,line-23,c
c,line-333a,d
a,line-4444,d
c,line-4a3ac,bb,dd
end
0 件のコメント:
コメントを投稿