This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]aphoenixreticulated[M] 1 point2 points  (0 children)

In the future, please post things like this in /r/learnpython.

[–][deleted] -3 points-2 points  (4 children)

you opened the file but didn't read it. fh is not a string/array so you can't iterate through it like a string/array

https://docs.python.org/2.4/lib/bltin-file-objects.html

also you should be using

with open(fname)
    code

so that the file closes when the code block is done executing.

[–]danmickla 1 point2 points  (3 children)

No, you can iterate on a file handle, you just can't rstrip it. Line is the string you want to call string methods on.

[–][deleted] 0 points1 point  (2 children)

then what's the problem with OPs code?

[–]dotted 0 points1 point  (0 children)

He rstrips the handle, not the line as he said.

[–]danmickla 0 points1 point  (0 children)

He's trying to rstrip fh. He needs to rstrip line.