[Tutor] Help with file I/O.

Nathan Pinno falcon3166 at hotmail.com
Sun Jul 31 22:39:59 CEST 2005


Just ran the code and got the following error:
File name please: news.text
Traceback (most recent call last):
  File "D:\Python22\filewriter.py", line 2, in ?
    f = file(file, "r")
TypeError: 'str' object is not callable

Why isn't it callable? Help me understand.
----- Original Message ----- 
From: "Nathan Pinno" <falcon3166 at hotmail.com>
To: "Danny Yoo" <dyoo at hkn.eecs.berkeley.edu>
Cc: <tutor at python.org>
Sent: Sunday, July 31, 2005 2:29 PM
Subject: Re: [Tutor] Help with file I/O.


> Here's my work. I call it filewriter.
> The code:
> file = raw_input("File name please: ")
> f = file(file, "r")
> for line in f.readlines():
>    print line
> f.close()
>
> Will it do the trick?
>
> Nathan
> ----- Original Message ----- 
> From: "Danny Yoo" <dyoo at hkn.eecs.berkeley.edu>
> To: "Nathan Pinno" <falcon3166 at hotmail.com>
> Cc: <tutor at python.org>
> Sent: Sunday, July 31, 2005 12:22 AM
> Subject: Re: [Tutor] Help with file I/O.
>
>
>>
>>
>> On Sun, 31 Jul 2005, Nathan Pinno wrote:
>>
>>> Well, you saw my password program. That was my first attempt at using
>>> file I/O. Thought I'd try it big time. You saw where that went.
>>
>> Ok, let's take a look.  It was from this message, right?
>>
>>    http://mail.python.org/pipermail/tutor/2005-July/039478.html
>>
>> That was such a while back that I think you probably learned a lot since
>> then, and I think a few of the issues there were less about I/O and more
>> about just general programming.
>>
>> Let's try a few things, just to see why you're getting stuck.  Can you
>> write a program that reads in a file, and just prints all of its lines 
>> out
>> to screen?
>>
>>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 


More information about the Tutor mailing list