[Tutor] Help with file I/O.

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


Okay I understand how to open and read to a file, but how do I write to a 
file, e.g. a list.
----- Original Message ----- 
From: "Nathan Pinno" <falcon3166 at hotmail.com>
To: "Nathan Pinno" <falcon3166 at hotmail.com>; "Danny Yoo" 
<dyoo at hkn.eecs.berkeley.edu>
Cc: <tutor at python.org>
Sent: Sunday, July 31, 2005 2:46 PM
Subject: Re: [Tutor] Help with file I/O.


> Here's the improved version.
> file = raw_input("File name please: ")
> f = open(file)
> for line in f.readlines():
>    print line
> f.close()
>
> ----- 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