Python 学习笔记(2)

Posted on 2014-03-26 23:23  wintor12  阅读(118)  评论(0编辑  收藏  举报

input and output

write lines:

p = open(dst, 'w+')
s=['12','34','56']
for a in s:
p.write(a + '\n')
p.close()

 

read lines:

p = open(dst, 'r')
# s = p.read()
# print s
content = p.readlines()
print content
p.close()

 

['12\n', '34\n', '56\n']

 

Remove '\n'

 

p = open(dst, 'r')
lines = [line.strip() for line in p]
print lines
p.close()

Copyright © 2024 wintor12
Powered by .NET 8.0 on Kubernetes