Check Carriage Return Is There In A Given String
i,m reading some lines from a file and i'm checking whether each line has windows type of CRLF or not. If either '\n' or '\r' is absent in any line, it has to report an error. I tr
Solution 1:
This isn't working because Loop_Counter
is never adjusted at all; whatever the initial value is, it's not changing and the while
loop either runs indefinitely or never passes. Your code is pretty unclear here; I'm not sure why you'd structure it that way.
What you're suggesting would be easier to do like this:
infile = open(filename, 'rb')
for index, line inenumerate(infile.readlines()):
if line[-2:] != '\r\n':
print index
The 'rb'
argument is necessary to make sure the newlines are read as \r\n
and not just as \n
.
Solution 2:
try this
Open_file = open(File_Name,'rb').readlines()
you have to open file in binary mode
Solution 3:
Should it be
if ('\r' not in Line_Read or '\n' not in Line_Read):
print Loop_Counter
?? Also, as jdotjdot pointed out, Loop_Counter is not incremented at all.
Post a Comment for "Check Carriage Return Is There In A Given String"