Paul McNett wrote:

> Ed Leafe wrote:
> 
>> On Jan 15, 2008, at 3:39 PM, Jeff Johnson wrote:
>> 
>>> Thank Ed.  But it IS a file object so I can pass it to:
>>>
>>>       cp = ConfigParser.ConfigParser()
>>>       cp.readfp(f)
>>>
>>> Right?  It appears to work fine.
>> 
>>      If you open it for write, it should be a zero-byte file. You would  
>> normally open the file for read (i.e., no parameter) before passing  
>> it to something that needs to read it.
> 
> AFAIK (but test it for yourself at the command line), you either open 
> files read-only or write-only. IOW, if I open a file with 'w', I can 
> write to it but not read from it. I just tried that and got an exception 
> trying to read from it 'bad file descriptor'.
> 
> If you want to open up a file to write to without first erasing its 
> contents, you use 'w+' mode.

Oops, back to Python 101 for me:

open("test", "r") -> read-only
open("test", "w") -> write-only
open("test", "w+") -> read/write
open("test", "a") -> append-only
open("test", "a+") -> append/read

There are additional mode codes, such as 'b' which tells it not to 
automatically add newlines, which is usually what you want.

Paul

-- 
http://paulmcnett.com


_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: http://leafe.com/archives/byMID/dabo-users/[EMAIL PROTECTED]

Reply via email to