Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Python 2.5 execfile() works only once, why ?

Reply
Thread Tools

Python 2.5 execfile() works only once, why ?

 
 
Stef Mientki
Guest
Posts: n/a
 
      10-09-2009
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

 
Reply With Quote
 
 
 
 
Carl Banks
Guest
Posts: n/a
 
      10-09-2009
On Oct 9, 11:15*am, Stef Mientki <(E-Mail Removed)> wrote:
> 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
 
Reply With Quote
 
 
 
 
Stef Mientki
Guest
Posts: n/a
 
      10-09-2009
thanks Carl,
in the mean while I found a good working solution thorugh wx.Execute.

cheers,
Stef

Carl Banks wrote:
> On Oct 9, 11:15 am, Stef Mientki <(E-Mail Removed)> wrote:
>
>> 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
>


 
Reply With Quote
 
Steven D'Aprano
Guest
Posts: n/a
 
      10-10-2009
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.


--
Steven
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
Python c-api and reusing python-objects: works only once karye2004@gmail.com Python 1 11-08-2006 09:42 PM
When I turn on my PC, it works, works, works. Problem! Fogar Computer Information 1 01-17-2006 12:57 AM
After rebooting my PC works, works, works! Antivirus problem? Adriano Computer Information 1 12-15-2003 05:30 AM



Advertisments