小编Asa*_*Kim的帖子

为什么 len(file.read()) 给我的值为零?

为什么这两个函数的 print len() 值不同?它们不一样吗?

此脚本打开的文件是一个包含三行文本的文本文件。我将它命名为 test.txt,里面是

Jack and Jill
gave up 
they went home with no water
Run Code Online (Sandbox Code Playgroud)

代码:

def function2nd (filename):
        target = open(theFile, 'r')
        inData = target.read()
        print inData
        print len(inData)
        target.close()
theFile = raw_input("What is the file name?\n>>")
function2nd(theFile)

def function3rd (filename):
        target = open(theFile, 'r')
        target.read()
        print target.read()
        print len(target.read())
        target.close()

function3rd(theFile)
Run Code Online (Sandbox Code Playgroud)

python file-io seek eof python-2.7

-5
推荐指数
1
解决办法
475
查看次数

标签 统计

eof ×1

file-io ×1

python ×1

python-2.7 ×1

seek ×1