首页 > 代码库 > python读取文件的常用方法

python读取文件的常用方法

#/usr/bin/env python
#-*-coding:UTF-8-*-

import sys 

"""读取文件的常用方法"""
def methodone():
	fd = open("/home/userhome/hejoy/20170124.txt")
	try:
		for line  in fd.readlines():
			print line
	except IOError:
		print e
	finally:
		fd.close()
def methodtwo():
	try:
		for line in open("/home/userhome/hejoy/20170124.txt"):
			print line
	except IOError:
		print e
		

def main():
	methodtwo()


if __name__==‘__main__‘:
	main()

  

python读取文件的常用方法