hello,
I've a graphical application (wxPython),
where the code in the main GUI loop is given below.
1 JAL_Loaded = False
2 while len(App_Running ) 0:
3 if JALsPy_globals. State == SS_Run:
4 try:
5 if JAL_Loaded:
6 reload ( JAL_simulation_ file )
7 else:
8 JAL_Loaded = True
9 import JAL_simulation_ file
10 except JALsPy_globals. Reload_Exceptio n:
11 JALsPy_globals. State = SS_Halt
The first time the while loop is entered,
JAL_Loaded is False (line 1),
and when I press some button,
the code will enter at line 8,
importing a module, that has executable code with an infinite loop.
To exit this infinite loop, an exception is generated (by a button press),
and program comes back in the above while-loop line (10,11,2).
So far so good.
Then I change the code in the imported file,
and when I start the engine again,
the flag JAL_Loaded is True, so I don't import,
but I reload the file.
Now I get the next exception
UnboundLocalErr or: local variable 'JAL_simulation _file' referenced before assignment
So obviously I can't reload but have to do an import again
(which makes the code much simpler ;-)
but I don't understand why the reload raises an exception ????
please enlighten me,
thanks,
Stef Mientki 3 1554
Stef Mientki wrote:
hello,
I've a graphical application (wxPython),
where the code in the main GUI loop is given below.
1 JAL_Loaded = False
2 while len(App_Running ) 0:
3 if JALsPy_globals. State == SS_Run:
4 try:
5 if JAL_Loaded:
6 reload ( JAL_simulation_ file )
7 else:
8 JAL_Loaded = True
9 import JAL_simulation_ file
10 except JALsPy_globals. Reload_Exceptio n:
11 JALsPy_globals. State = SS_Halt
The first time the while loop is entered,
JAL_Loaded is False (line 1),
and when I press some button,
the code will enter at line 8,
importing a module, that has executable code with an infinite loop.
To exit this infinite loop, an exception is generated (by a button press),
and program comes back in the above while-loop line (10,11,2).
So far so good.
Then I change the code in the imported file,
and when I start the engine again,
the flag JAL_Loaded is True, so I don't import,
but I reload the file.
Now I get the next exception
UnboundLocalErr or: local variable 'JAL_simulation _file' referenced before assignment
So obviously I can't reload but have to do an import again
(which makes the code much simpler ;-)
but I don't understand why the reload raises an exception ????
You have an assignment to JAL_simulation_ file elsewhere inside the same
function, later in the code. This means that Python will assume that it
is local to the function, but the import statement will affect the
module namespace rather than the function namespace.
In other words, your code is roughly equivalent to what follows, with
the added complexity that the illegal reference isn't triggered until
the second iteration of a loop.
>>def f():
.... print os
.... import os
.... os = "Something"
....
>>f()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in f
UnboundLocalErr or: local variable 'os' referenced before assignment
>>>
The solution? Don't assign to JAL_simulation_ file, and the function will
use the local instead.
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------
Steve Holden wrote:
[...]
The solution? Don't assign to JAL_simulation_ file, and the function will
use the local instead.
Sorry, that last "local" should have been "global".
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------
Steve Holden wrote:
Stef Mientki wrote:
>hello,
I've a graphical application (wxPython), where the code in the main GUI loop is given below.
1 JAL_Loaded = False 2 while len(App_Running ) 0: 3 if JALsPy_globals. State == SS_Run: 4 try: 5 if JAL_Loaded: 6 reload ( JAL_simulation_ file ) 7 else: 8 JAL_Loaded = True 9 import JAL_simulation_ file 10 except JALsPy_globals. Reload_Exceptio n: 11 JALsPy_globals. State = SS_Halt
The first time the while loop is entered, JAL_Loaded is False (line 1), and when I press some button, the code will enter at line 8, importing a module, that has executable code with an infinite loop.
To exit this infinite loop, an exception is generated (by a button press), and program comes back in the above while-loop line (10,11,2).
So far so good.
Then I change the code in the imported file, and when I start the engine again, the flag JAL_Loaded is True, so I don't import, but I reload the file.
Now I get the next exception UnboundLocalErr or: local variable 'JAL_simulation _file' referenced before assignment
So obviously I can't reload but have to do an import again (which makes the code much simpler ;-) but I don't understand why the reload raises an exception ????
You have an assignment to JAL_simulation_ file elsewhere inside the same
function,
No these are the only 2 uses of "JAL_simulation _file" in the whole project.
later in the code. This means that Python will assume that it
is local to the function, but the import statement will affect the
module namespace rather than the function namespace.
In other words, your code is roughly equivalent to what follows, with
the added complexity that the illegal reference isn't triggered until
the second iteration of a loop.
>>def f():
... print os
... import os
... os = "Something"
...
>>f()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in f
UnboundLocalErr or: local variable 'os' referenced before assignment
>>>
The solution? Don't assign to JAL_simulation_ file, and the function will
use the local instead.
The solution is much simpler, but I don't understand why the "import",
which really reloads the changed code in JAL_simulation_ file,
works the second time :-(
2 while len(App_Running ) 0:
3 if JALsPy_globals. State == SS_Run:
4 try:
9 import JAL_simulation_ file
10 except JALsPy_globals. Reload_Exceptio n:
11 JALsPy_globals. State = SS_Halt
cheers,
Stef Mientki This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Ellinghaus, Lance |
last post by:
> > Other surprises: Deprecating reload()
>Reload doesn't work the way most people think
>it does: if you've got any references to the old module,
>they stay around. They aren't replaced.
>It was a good idea, but the implementation simply
>doesn't do what the idea promises.
I agree that it does not really work as most people think it does, but how
|
by: Emmanuel |
last post by:
Hi,
I use a 'reload all' feature in my app, that allow to reload every
module.
I first try this version :
import sys
def Reload():
|
by: Cooper |
last post by:
Hello,
is possible to disable the reload (or update, for ie) of the a web page? If
yes, what i do? Otherwise if isn't possible, what i do for to set the
default value of a form when a user do a reload of update of the web page?
Thank you, Cooper.
|
by: fhiemstra0507 |
last post by:
Hi
I have a listbox that I want to update when the an item is updated/added.
Now the listbox is attached to a query. Now I tried to just reload the
query by modifying the forms loadDataSet and filldataset subroutines but
when I do that the table values do not mesh which the lstbox anymore. As
well, I have looked at the data adapters select statement to try and update
it but to no avail.
Any suggestions?
|
by: Alan Z. Scharf |
last post by:
1. I have a chain of six asynch callbacks initiated by a button, and want
the page to refresh at the end of each callback to display
A. Results of a SQLServer query showing cumulative running time, and
B. A progress bar.
2. I have this working with a refresh timer:
<META http-equiv="refresh" content="5">
| |
by: gen_tricomi |
last post by:
Python 2.4.2 (#67, Sep 28 2005, 12:41:11)
on win32
Type "copyright", "credits" or "license()" for more information.
****************************************************************
Personal firewall software may warn about the connection IDLE
makes to its subprocess using this computer's internal loopback
interface. This connection is not visible on any external
interface and no data is sent to or received from the Internet....
|
by: fdu.xiaojf |
last post by:
Hi,
I have a program which will continue to run for several days. When it is
running, I can't do anything except waiting because it takes over most
of the CUP time.
Is it possible that the program can save all running data to a file when
I want it to stop, and can reload the data and continue to run from
where it stops when the computer is free ?
|
by: nkoriginal |
last post by:
Hello Again:
I've a problem with my forms. I woking with an intranet, and the pages in that intranet, has a reload page, every 10 minutos.
So my problems star, when any user stay in my forms for more longe than 10 minutes, and the page reload, the user lose all data in that forms, if he not did submit.
I want to keep the user form data, after reload. Is that possible?
so, en litle words, if the user stay in my forms and he filled...
|
by: Max |
last post by:
Is it possible to reload a web page on user browser when an event occurs at
server side?
For example when user A places an order, user B should be notified of that
and should see that order on his page.
I 'd like to avoid to reload B page every nnn seconds. Or at least, I'd like
to check if something interesting has changed on server and only in that
case to reload the page.
Any suggestion?
Thanks Max
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |