Re: Executing global code

2009-01-15 Thread MRAB
Steven D'Aprano wrote: > On Thu, 15 Jan 2009 17:50:54 +0100, Peter Otten wrote: > >> Jakub Debski wrote: >> >>> Is it possible to execute global code (module-level code) more than >>> once keeping the state of global variables? This means no reload() and >>> no moving the code to a function. >> Yo

Re: Executing global code

2009-01-15 Thread Steven D'Aprano
On Thu, 15 Jan 2009 17:50:54 +0100, Peter Otten wrote: > Jakub Debski wrote: > >> Is it possible to execute global code (module-level code) more than >> once keeping the state of global variables? This means no reload() and >> no moving the code to a function. > > You have a module containing e.

Re: Executing global code

2009-01-15 Thread Terry Reedy
Jakub Debski wrote: Hi, Is it possible to execute global code (module-level code) more than once keeping the state of global variables? This means no reload() and no moving the code to a function. Wrap the code in a loop: for dummy in range(): # a plural count literal tjr -- http://ma

Re: Executing global code

2009-01-15 Thread Zac Burns
I'm not sure I fully understand the question "no moving the code to a function", but you can prevent reload in a module by doing something like this: doLoad = False try: no_reload except NameError: no_reload = True else: raise RuntimeError, "This module is not meant to be reloaded." -- Zach

Executing global code

2009-01-15 Thread Jakub Debski
Hi, Is it possible to execute global code (module-level code) more than once keeping the state of global variables? This means no reload() and no moving the code to a function. regards, Jakub -- http://mail.python.org/mailman/listinfo/python-list

Re: Executing global code

2009-01-15 Thread Zac Burns
The first line: doLoad = False, is to be ignored. -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games On Thu, Jan 15, 2009 at 10:30 AM, Zac Burns wrote: > I'm not sure I fully understand the question "no moving the code to a > function", but you ca

Re: Executing global code

2009-01-15 Thread Peter Otten
Jakub Debski wrote: > Is it possible to execute global code (module-level code) more than > once keeping the state of global variables? This means no reload() and > no moving the code to a function. You have a module containing e. g. these two statements x = 42 x += 1 and want to rerun it with