Python 2.5 execfile() works only once, why ?

Discussion in 'Python' started by Stef Mientki, Oct 9, 2009.

  1. Stef Mientki

    Stef Mientki Guest

    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
    Stef Mientki, Oct 9, 2009
    #1
    1. Advertising

  2. Stef Mientki

    Carl Banks Guest

    On Oct 9, 11:15 am, Stef Mientki <> 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
    Carl Banks, Oct 9, 2009
    #2
    1. Advertising

  3. Stef Mientki

    Stef Mientki Guest

    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 <> 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
    >
    Stef Mientki, Oct 9, 2009
    #3
  4. 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
    Steven D'Aprano, Oct 10, 2009
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Scott Townsend
    Replies:
    2
    Views:
    4,331
  2. Guy
    Replies:
    5
    Views:
    4,496
    Bob Rivers
    Dec 11, 2003
  3. Brandon
    Replies:
    4
    Views:
    9,054
    John Harrison
    Jun 23, 2004
  4. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,655
    Smokey Grindel
    Dec 2, 2006
  5. Replies:
    1
    Views:
    393
    Gabriel Genellina
    Nov 8, 2006
Loading...

Share This Page