Я хочу знать номера строк определенного файла. Ниже приведен код
Но результат неверный: Истинный номер строки файла == Номер результата консоли + 1
проблема в "open().readlines()"?
если в последней строке есть содержимое, результат правильный
import os
import os.path
absPath = os.curdir
while True:
print '\nplease select the file you want to know the line nums:'
print os.listdir(absPath)
fileName = raw_input()
absFilePath = absPath + '//' + fileName
if os.path.isfile(absFilePath):
count = len(open(absFilePath).readlines())
print 'the ' + fileName + ' file line nums is>>>' + str(count) + '>>>'
else:
print 'Please check the fileName or the input is not a file'
len(open('file.txt').read().splitlines())
- person sashoalm   schedule 06.03.2014