python獲取文件行數
給定一個文件,獲取文件行數方法:代碼如下
# 打開一個文件,read權限
file = open('/home/users/wangkaikai/a.txt', 'r')
count = 0
for line in file:
count += 1
# 一定要關閉文件
file.close()
print '文件行數 = ' + str(count)
給定一個文件,獲取文件行數方法:代碼如下
# 打開一個文件,read權限
file = open('/home/users/wangkaikai/a.txt', 'r')
count = 0
for line in file:
count += 1
# 一定要關閉文件
file.close()
print '文件行數 = ' + str(count)
本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。