码迷,mamicode.com
首页 > 编程语言 > 详细

Python之读取TXT文件的三种方法

时间:2018-05-04 12:01:29      阅读:242      评论:0      收藏:0      [点我收藏+]

标签:读取txt

参考了https://blog.csdn.net/shandong_chu/article/details/70173952

-- coding: UTF-8 --

import sys

方法一:
#read txt method one
f = open("./image/abc.txt")
line = f.readline()
while line:
print line
line = f.readline()
f.close()

方法二:
#read txt method two
f = open("./image/abc.txt")
for line2 in open("./image/abc.txt"):
print line2

方法三:
#read txt method three
f2 = open("./image/abc.txt","r")
lines = f2.readlines()
for line3 in lines:
print line3

Python之读取TXT文件的三种方法

标签:读取txt

原文地址:http://blog.51cto.com/406647516/2112589

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!