Python:Detect if the current line in file read is the last one -


I am reading a file in a Python line through a line and I need to know which during reading Line is the last, something like this:

  f = for the line in the open ("myfile.txt") f: if the line is the last line: #d smth  

I found it to complete and complete the files to count the lines, etc. Do I just find out that the current line is last? I tried to go and check "\ n" existence, but in many cases backlash of previous lines has not been en.

Sorry if my question is unhelpful because I did not get the answer

  SecondLastLine = None None with LastLine = Open ("myfile.txt") as infile: Second Listline, Last Line = Infil.Redline (), infile.readline () for row in Infill: # dot Stuff secondsLastline = Last Line LastLine = Line #Last LastLine  

Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -