Python中tell()方法的使用詳解
tell()方法返回的文件內(nèi)的文件讀/寫指針的當(dāng)前位置。
語法
以下是tell()方法的語法:
fileObject.tell()
參數(shù)
- NA
返回值
此方法返回該文件中讀出的文件/寫指針的當(dāng)前位置。
例子
下面的例子顯示了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()
當(dāng)我們運(yùn)行上面的程序,它會產(chǎn)生以下結(jié)果:
Name of the file: foo.txt Read Line: This is 1st line Current Position: 18
相關(guān)文章
python使用rstrip函數(shù)刪除字符串末位字符
rstrip函數(shù)用于刪除字符串末位指定字符,默認(rèn)為空白符,這篇文章主要介紹了python使用rstrip函數(shù)刪除字符串末位字符的方法,需要的朋友可以參考下2023-04-04Selenium+Python 自動化操控登錄界面實(shí)例(有簡單驗(yàn)證碼圖片校驗(yàn))
今天小編就為大家分享一篇Selenium+Python 自動化操控登錄界面實(shí)例(有簡單驗(yàn)證碼圖片校驗(yàn)),具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-06-06Python中selenium實(shí)現(xiàn)文件上傳所有方法整理總結(jié)
本篇文章主要介紹了Python中selenium實(shí)現(xiàn)文件上傳所有方法整理總結(jié),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。2017-04-04python線程鎖(thread)學(xué)習(xí)示例
python thread提供了低級別的、原始的線程以及一個(gè)簡單的鎖,下面提供一個(gè)python線程線程鎖(thread)學(xué)習(xí)示例,大家參考使用2013-12-12Django中對數(shù)據(jù)查詢結(jié)果進(jìn)行排序的方法
這篇文章主要介紹了Django中對數(shù)據(jù)查詢結(jié)果進(jìn)行排序的方法,利用Python代碼代替SQL進(jìn)行一些簡單的操作,需要的朋友可以參考下2015-07-07深入學(xué)習(xí)python的yield和generator
這篇文章主要為大家詳細(xì)介紹了python的yield和generator,針對python的生成器和yield關(guān)鍵字進(jìn)行深入學(xué)習(xí),感興趣的小伙伴們可以參考一下2016-03-03