Python 2.5 execfile() works only once, why ?

S

Stef Mientki

hello,

I'm working on a kind of IDE, to build and distribute Python programs.

One of the parts is editing a build file for py2exe and running the
modified script.

In the script editor I've an accelerator key, to launch these tasks:
- save modified script file
- run modified script file
- catch log and error information from py2exe
- launch the distro executable

self.Edit.SaveFile ( self.Edit.Filename )
Globalsx = {}
#Globalsx [ 'stdout' ] = self.Log
execfile ( self.Edit.Filename, Globalsx )

The above code (with or without the stdout redirection),
works perfect, ....
.... the first time ...
but does (almost?) nothing (doesn't crash, try / except around execfile),
although the source file "self.Edit.Filename" has changed.

Could someone give me an explanation, why this happens ?

It would be great to have a work around.
I've currently switched to Popen, but can't get output / error piping
working fluently.

thanks,
Stef Mientki
 
C

Carl Banks

hello,

I'm working on a kind of IDE, to build and distribute Python programs.

One of the parts is editing a build file for py2exe and running the
modified script.

In  the script editor I've an accelerator key, to launch these tasks:
- save modified script file
- run modified script file
- catch log and error information from py2exe
- launch the distro executable

      self.Edit.SaveFile ( self.Edit.Filename )
      Globalsx = {}
      #Globalsx [ 'stdout' ]  = self.Log
      execfile ( self.Edit.Filename, Globalsx  )

The above code (with or without the stdout redirection),
works perfect, ....
... the first time ...
but does (almost?) nothing (doesn't crash, try / except around execfile),
although the source file "self.Edit.Filename" has changed.

Could someone give me an explanation, why this happens ?

I'm guessing you have references to objects from the first time you
ran execfile that don't get updated. It's kind of hard to tell.


Carl Banks
 
S

Stef Mientki

thanks Carl,
in the mean while I found a good working solution thorugh wx.Execute.

cheers,
Stef

Carl said:
hello,

I'm working on a kind of IDE, to build and distribute Python programs.

One of the parts is editing a build file for py2exe and running the
modified script.

In the script editor I've an accelerator key, to launch these tasks:
- save modified script file
- run modified script file
- catch log and error information from py2exe
- launch the distro executable

self.Edit.SaveFile ( self.Edit.Filename )
Globalsx = {}
#Globalsx [ 'stdout' ] = self.Log
execfile ( self.Edit.Filename, Globalsx )

The above code (with or without the stdout redirection),
works perfect, ....
... the first time ...
but does (almost?) nothing (doesn't crash, try / except around execfile),
although the source file "self.Edit.Filename" has changed.

Could someone give me an explanation, why this happens ?

I'm guessing you have references to objects from the first time you
ran execfile that don't get updated. It's kind of hard to tell.


Carl Banks
 
S

Steven D'Aprano

On Fri, 09 Oct 2009 20:15:48 +0200, Stef Mientki wrote:

[...]
The above code (with or without the stdout redirection), works perfect,
....
... the first time ...
but does (almost?) nothing (doesn't crash, try / except around
execfile), although the source file "self.Edit.Filename" has changed.


What do you mean "doesn't crash, try / except around execfile"? Are you
*expecting* it to crash?

Are you catching an error and suppressing it? What happens if you remove
the try...except? Are you sure that execfile is actually being called?
How do you know?

Are you running your code inside an IDE? If so, it's possible the IDE is
doing something funny.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top