Python: file.readline adding a space at the end of the line
<p>Am using python to read a flat space-padded text file. Part of the validation of the text file is that each line in the text file is expected to be a specific file length including the space padding.</p>

<p>When I use the following code, python ends up giving me a line with an extra space. E.g. I expect all the rows in fileX to have 143 characters. Python though will read this as 144 characters and thus say the file is invalid. If I do the same in VB.NET, I get the correct 143 characters.</p>

<p>Why is <strong>Python's</strong> readline function adding an extra character? (Using python 3.2)</p>

<pre><code>import io
myfile = open("file_path", "r")
while True:
    line = myfile.readline()
    if not line:
            break
    print(len(line))  #This prints 144 characters
</code></pre>

<p><strong>VB.NET</strong> gives the correct length of 143 characters.</p>

<pre><code>Using objStreamReader As StreamReader = New StreamReader(myFilePath)
    While objStreamReader.EndOfStream = False
            line = objStreamReader.ReadLine
            len(line)   'This returns the correct length of 143.
</code></pre>

<p>Using line.strip will not be the right mechanism because I might get rid of useful spaces. Remember the file is space-padded up to a maximum given length.</p>
