469,955 Members | 2,157 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,955 developers. It's quick & easy.

Re: UnboundLocalError problems

Mr SZ wrote:

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.Here's the code:

#!/usr/bin/env python

import dbus, gobject
from dbus.mainloop.glib import DBusGMainLoop
dbus.mainloop.glib.DBusGMainLoop(set_as_default=Tr ue)
bus = dbus.SessionBus()

obj = bus.get_object("im.pidgin.purple.PurpleService",
purple = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface")

def my_func2(IsEnabled):
you need
if IsEnabled:
ORIG_TYPE,ORIG_MSG = get_current()
because this otherwise marks them as local.

When I run it,it errors out at :


giving the error "UnboundLocalError: local variable 'ORIG_TYPE'
referenced before assignment" .This happens
In the future, copy and paste the full traceback, which often has
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?Everything works fine if I set the arguments manually to the
set_status function.
*Any* assignment to a name, including with def, class, import, and
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).


Jun 29 '08 #1
0 966

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Brad Clements | last post: by
6 posts views Thread by Alex Gittens | last post: by
2 posts views Thread by silverburgh.meryl | last post: by
8 posts views Thread by David Bear | last post: by
15 posts views Thread by Paddy | last post: by
9 posts views Thread by Camellia | last post: by
2 posts views Thread by Konstantinos Pachopoulos | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.