这样写为什么打印不出来数组内容,但是打印出来一共有多少个元素了
def dayin(x,y):listOne = y.split(':')
one = listOne
two = listOne
len1 = len(one)
len2 = len(two)
oneFile = open(x,'r', encoding='UTF-8')
alllines = len(oneFile.readlines())
onelist = oneFile.readlines()
print('读取文件的内容%s++++%s' % (onelist,alllines))
# x 是文件路径 def dayin(x,y):
listOne = y.split(':')
one = listOne
two = listOne
len1 = len(one)
len2 = len(two)
oneFile = open(x,'r', encoding='UTF-8')
onelist = oneFile.readlines()
alllines = len(onelist)
print('读取文件的内容%s++++%s' % (onelist,alllines))
因为你读取了一次(len那里),这时候文件指针已经到末尾了
第一种可以用楼上的方法,第二种可以试试f.seek(0,0)? 因为你readlines 两次,read和readlines 会改变文件的‘指针’位置,如果你读到最后,下一次就是空的
def dayin(x,y):
listOne = y.split(':')
one = listOne
two = listOne
len1 = len(one)
len2 = len(two)
oneFile = open(x,'r', encoding='UTF-8')
onelist = oneFile.readlines()
alllines = len(onelist)
print('读取文件的内容%s++++%s' % (onelist,alllines))
页:
[1]