python - Count the line number of file -


i want count file lines.

i have googoled around , found 2 ways in vane

test = open('./log/test.csv','a')  if sum(1 line in test) == 0:     print("no line") 

shows

io.unsupportedoperation: not readable 

second way

test = open('./log/test.csv','a')  if len(test.readlines()) == 0:     print("no line") 

it shows error too.

try doing:

test = open('./log/test.csv', 'r') 

the issue don't have on read mode


Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -