读目录文件名:
import os
import io
def eachFile(filepath):
pathDir = os.listdir(filepath)
for allDir in pathDir:
child = os.path.join('%s%s' % (filepath, allDir))
print child.decode('gbk') # .decode('gbk')是解决中文显示乱码问题
打印文件内容:
# 读取文件内容并打印
def readFile(filename):
fopen = open(filename, 'r') # r 代表read
for eachLine in fopen:
print "读取到得内容如下:", eachLine
fopen.close()
def files:
fopen = io.open(filepath, 'r', encoding='gbk') # r 代表read
while True:
fopen1 = fopen.readline()
if fopen1:
print fopen1
else:
break
fopen.close()