## Replace the ... text below with a title and a summary of the problem.
## Feel free to remove any remaining comments once you're done!

= Asking for Help: Why when I read a text file python reads it as "<built-in method read of _io.TextIOWrapper object at 0x02954558>" and how do I stop this? =

I am writing a program that uses text files to store user information like their name and password.  I am using this information to check login info against the info they have provided.  This never worked so I decided to do a simple open files program to find the problem.

{{{#!python
f = open('test.txt', 'r')
a = f.read
f.close
print(a)
}}}
and when I ran it on Idle it printed:
<built-in method read of _io.TextIOWrapper object at 0x02954558>
Instead of what I had in my text file.  Does anyone know why this is happening or how to stop it?
## {{{#!python
## ...
## }}}

----

You have to actually call the `read` method as follows:

{{{#!python numbers=disable
a = f.read()
}}}

The brackets are important because they tell Python to actually ''call'' the method, and this produces the content of the file to be assigned to `a`. If you don't have the brackets, all you are doing is obtaining the `read` method and assigning it to `a`. Thus, when you print `a` you see a piece of text describing the method (which is what `<built-in method read of _io.TextIOWrapper object at 0x02954558>` means) instead of the content of the file.

So the point to remember is this: referring to the method (like with `f.read`) just lets you obtain the method, but if you want to call the method, you have to add brackets. The following also works:

{{{#!python numbers=disable
method = f.read
a = method()
}}}


Here, we split up the part where you get the method from the part where you call the method. There really are two different things going on. -- PaulBoddie <<DateTime(2011-12-17T19:41:14+0100)>>

----
CategoryAskingForHelp CategoryAskingForHelpAnswered