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):
you need
global ORIG_TYPE,ORIG_ MSG
if IsEnabled:
ORIG_TYPE,ORIG_ MSG = get_current()
because this otherwise marks them as local.
[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
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?Everythin g 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).
tjr 0 1108 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Brad Clements |
last post by:
I was going to file this as a bug in the tracker, but maybe it's not really
a bug. Poor Python code does what I consider to be unexpected. What's your
opinion?
With Python 2.3.2 (but also happens with 2.2)
An import within a function that shadows a global import can raise
UnboundLocalError. I think the real problem is that the the local...
|
by: Alex Gittens |
last post by:
I'm trying to define a function that prints fields of given widths
with specified alignments; to do so, I wrote some helper functions
nested inside of the print function itself. I'm getting an
UnboundLocalError, and after reading the Naming and binding section in
the Python docs, I don't see why.
Here's the error:
>>> fieldprint(, 'rl', )...
|
by: silverburgh.meryl |
last post by:
Can you please tell me what is the meaning this error in general?
UnboundLocalError: local variable 'colorIndex' referenced before
assignment
In my python script,
I have a variable define and init to 0, like this
colorIndex = 0
and in one of my functions, I increment it by 1
|
by: David Bear |
last post by:
I'm attempting to use the cgi module with code like this:
import cgi
fo = cgi.FieldStorage()
# form field names are in the form if 'name:part'
keys = fo.keys()
for i in keys:
try:
item,value=i.split(':')
except NameError, UnboundLocalError:
|
by: Paddy |
last post by:
Hi,
I am trying to work out why I get UnboundLocalError when accessing an
int from a function where the int is at the global scope, without
explicitly declaring it as global but not when accessing a list in
similar circumstances.
The documentation: http://docs.python.org/ref/naming.html does not give
me enough info to determine why the...
| |
by: Camellia |
last post by:
hi all
why it generates an "UnboundLocalError" when I do the following:
<code>
....
def main():
number = number()
number_user = user_guess()
while number_user != number:
|
by: Konstantinos Pachopoulos |
last post by:
Hi,
i have a problem, the source of which is probably the fact, that i have
not understood how to declare global variables - I use the Jython
compiler, but i think this is a Python issue...
First of all, i don not use any classes in this module. The problem is,
that i declare and instantiate some vars outside the functions (global
ones),...
|
by: defn noob |
last post by:
isPrime works when just calling a nbr but not when iterating on a
list, why? adding x=1 makes it work though but why do I have to add
it?
Is there a cleaner way to do it?
def isPrime(nbr):
for x in range(2, nbr + 1):
if nbr % x == 0:
break
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
| |
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...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
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...
|
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...
| |