[Pythonmac-SIG] Re-opening files?

Chris Barker cbarker@jps.net
Tue, 07 Mar 2000 14:53:21 -0800


Hi Folks,

I am having a problem (more of an annoyance actually) when I try to
re-open a file that I am writing to. I get an erro when I do this:

file = open('filename','wt')
file.write('some stuff\n')

file = open('filename','wt')

I get an " IOError: [Errno 22] INvalid agrument 'filename' "



why would I want to do something as stupid as this? you might ask.

Well, strickly speaking, I don't. The problem is that if I am running a
script in the IDE, and it crashes after opening a file for writing, but
before closing it, then when I go to run the script again, I get this
erro. This requires me to go back, selct the file.close() line, run it,
and then run the script again. Again, mostly an annoyance, but I seem to
run into it A LOT.

By the way, the above code works just fine on Linux. Python appears to
just re-wind the file (probably just the output buffer), without erasing
it. Curious behavior, but it works for me!

While I'm at it, other IDE questions:

Is there a way to get the output window in the IDE to be interactive? I
often would like to use the command line after my script terminates to
check something out, but there is no way to do this.

Also, is there an easy way to change the working directory in the IDE
interactive window? import os, os.chdir('the whole path') is kind of a
pain.

-Chris

-- 
Christopher Barker,
Ph.D.                                                           
cbarker@jps.net                      ---           ---           ---
http://www.jps.net/cbarker          -----@@       -----@@       -----@@
                                   ------@@@     ------@@@     ------@@@
Water Resources Engineering       ------   @    ------   @   ------   @
Coastal and Fluvial Hydrodynamics -------      ---------     --------    
------------------------------------------------------------------------
------------------------------------------------------------------------