Python中tell()方法的使用詳解
更新時間:2015年05月24日 17:29:26 投稿:goldensun
這篇文章主要介紹了Python中tell()方法的使用詳解,是Python入門學習中的基礎知識,需要的朋友可以參考下
tell()方法返回的文件內的文件讀/寫指針的當前位置。
語法
以下是tell()方法的語法:
fileObject.tell()
參數(shù)
- NA
返回值
此方法返回該文件中讀出的文件/寫指針的當前位置。
例子
下面的例子顯示了tell()方法的使用。
#!/usr/bin/python
# Open a file
fo = open("foo.txt", "rw+")
print "Name of the file: ", fo.name
# Assuming file has following 5 lines
# This is 1st line
# This is 2nd line
# This is 3rd line
# This is 4th line
# This is 5th line
line = fo.readline()
print "Read Line: %s" % (line)
# Get the current position of the file.
pos = fo.tell()
print "Current Position: %d" % (pos)
# Close opend file
fo.close()
當我們運行上面的程序,它會產生以下結果:
Name of the file: foo.txt Read Line: This is 1st line Current Position: 18
相關文章
python使用rstrip函數(shù)刪除字符串末位字符
rstrip函數(shù)用于刪除字符串末位指定字符,默認為空白符,這篇文章主要介紹了python使用rstrip函數(shù)刪除字符串末位字符的方法,需要的朋友可以參考下2023-04-04
Selenium+Python 自動化操控登錄界面實例(有簡單驗證碼圖片校驗)
今天小編就為大家分享一篇Selenium+Python 自動化操控登錄界面實例(有簡單驗證碼圖片校驗),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-06-06
Python中selenium實現(xiàn)文件上傳所有方法整理總結
本篇文章主要介紹了Python中selenium實現(xiàn)文件上傳所有方法整理總結,具有一定的參考價值,感興趣的小伙伴們可以參考一下。2017-04-04
Django中對數(shù)據(jù)查詢結果進行排序的方法
這篇文章主要介紹了Django中對數(shù)據(jù)查詢結果進行排序的方法,利用Python代碼代替SQL進行一些簡單的操作,需要的朋友可以參考下2015-07-07

