Mr SZ wrote:
>
Hi,
>
I am writing a small script that changes my pidgin status to away when I
lock my screen.I'm using the DBUS API for pidgin and
gnome-screensaver.Her e's the code:
>
#!/usr/bin/env python
>
import dbus, gobject
from dbus.mainloop.g lib import DBusGMainLoop
dbus.mainloop.g lib.DBusGMainLo op(set_as_defau lt=True)
bus = dbus.SessionBus ()
>
obj = bus.get_object( "im.pidgin.purp le.PurpleServic e",
"/im/pidgin/purple/PurpleObject")
purple = dbus.Interface( obj, "im.pidgin.purp le.PurpleInterf ace")
>
>
STATUS_AVAILABL E = 2
STATUS_AWAY = 5
>
ORIG_TYPE = 0
ORIG_MSG = ""
>
>
def my_func2(IsEnab led):
Hi,
>
I am writing a small script that changes my pidgin status to away when I
lock my screen.I'm using the DBUS API for pidgin and
gnome-screensaver.Her e's the code:
>
#!/usr/bin/env python
>
import dbus, gobject
from dbus.mainloop.g lib import DBusGMainLoop
dbus.mainloop.g lib.DBusGMainLo op(set_as_defau lt=True)
bus = dbus.SessionBus ()
>
obj = bus.get_object( "im.pidgin.purp le.PurpleServic e",
"/im/pidgin/purple/PurpleObject")
purple = dbus.Interface( obj, "im.pidgin.purp le.PurpleInterf ace")
>
>
STATUS_AVAILABL E = 2
STATUS_AWAY = 5
>
ORIG_TYPE = 0
ORIG_MSG = ""
>
>
def my_func2(IsEnab led):
global ORIG_TYPE,ORIG_ MSG
if IsEnabled:
ORIG_TYPE,ORIG_ MSG = get_current()
ORIG_TYPE,ORIG_ MSG = get_current()
[snip]
When I run it,it errors out at :
>
set_status(ORIG _TYPE,ORIG_MSG)
>
giving the error "UnboundLocalEr ror: local variable 'ORIG_TYPE'
referenced before assignment" .This happens
>
set_status(ORIG _TYPE,ORIG_MSG)
>
giving the error "UnboundLocalEr ror: local variable 'ORIG_TYPE'
referenced before assignment" .This happens
additional useful information -- like the line # of the call -- which is
not so obvious to someone who has not read the code.
>
Aren't ORIG_TYPE and ORIG_MSG global variables? Where am I going
wrong?Everythin g works fine if I set the arguments manually to the
set_status function.
Aren't ORIG_TYPE and ORIG_MSG global variables? Where am I going
wrong?Everythin g works fine if I set the arguments manually to the
set_status function.
augmented assignment, even if the statement is unreachable and cannot be
executed, marks the name as local -- unless you specify it as global (or
nonlocal in 3.0).
tjr