黄色电影一区二区,丰满熟妇AV,97成人资源,日韩在线性爱

Python File tell() 方法

python file tell() 方法

python file 方法python file 方法

tell() 方法返回文件的當(dāng)前位置,即文件指針當(dāng)前位置。

語法

tell() 方法語法如下:

fileobject.tell()

參數(shù)

返回值

返回文件的當(dāng)前位置。

實例

以下實例演示了 tell() 方法的使用:

文件 codebaoku.txt 的內(nèi)容如下:

1:www.ailvzhou.com
2:www.ailvzhou.com
3:www.ailvzhou.com
4:www.ailvzhou.com
5:www.ailvzhou.com

循環(huán)讀取文件的內(nèi)容:

#!/usr/bin/python
# -*- coding: utf-8 -*-

# 打開文件
fo = open("codebaoku.txt", "rw+")
print "文件名為: ", fo.name

line = fo.readline()
print "讀取的數(shù)據(jù)為: %s" % (line)

# 獲取當(dāng)前文件位置
pos = fo.tell()
print "當(dāng)前位置: %d" % (pos)


# 關(guān)閉文件
fo.close()

以上實例輸出結(jié)果為:

文件名為:  codebaoku.txt
讀取的數(shù)據(jù)為: 1:www.ailvzhou.com

當(dāng)前位置: 20

python file 方法python file 方法

下一節(jié):python file truncate() 方法

python 教程

相關(guān)文章