473,785 Members | 2,369 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Weird local variables behaviors

Hey,

can someone please explain this behavior:

The code:

def test1(value=1):
def inner():
print value
inner()
def test2(value=2):
def inner():
value = value
inner()

test1()
test2()

[trepca@sauron ~/dev/tests]$ python locals.py
1
Traceback (most recent call last):
File "locals.py" , line 13, in <module>
test2()
File "locals.py" , line 10, in test2
inner()
File "locals.py" , line 9, in inner
value = value
UnboundLocalErr or: local variable 'value' referenced before assignment

Why can't he find the variable in the second case?
Thanks, Sebastjan
Jun 27 '08 #1
0 781

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1635
by: Catherine Lynn Wood | last post by:
I have a page that I just developed using a combination of stylesheets and div layers. It uses a 'tab' style system placing four div layers in the same space with visibility 'hidden' and position absolute. They are inside of another parent div container with position set relative so that as I make the objects visible, I can also set their position to relative so they redraw the container size. The parent div is inside of a table cell...
5
4016
by: news | last post by:
I've a site: http://gto.ie-studios.net/products.php that looks perfectly fine in Windows whether with IE or Firefox 1.0. But when viewed in the Linux version of Firefox 1.0, images get misaligned and breaks between then appear. Why the two different behaviors on the same browser but different OS's? Anyway, that page as an example DOES W3C HTML validate AND W3C CSS validate as well. So, there's no ERRORS per se, but I suppose there's...
82
5389
by: nobody | last post by:
Howdy, Mike! mikecoxlinux@yahoo.com (Mike Cox) wrote in message news:<3d6111f1.0402271647.c20aea3@posting.google.com>... > I'm a C++ programmer, and have to use lisp because I want to use > emacs. I've gotten a book on lisp, and I must say lisp is the ugliest > looking language syntax wise. What is up with this: (defun(foo()). (DEFUN FOO () NIL) > What were the lisp authors thinking? Why did Stallman use lisp in
5
1670
by: Tommytrojan | last post by:
Hi, I have been using Python for a while but today I came across a really strange behavior: While poking around in Queue.py due to problems with importing this module from a thread I got an error that a module that I imported on top of the file could not be accessed. I reduced the problem to this small script:
2
2322
by: Nils Emil P. Larsen | last post by:
Hello I have read about a C shared library which I want to use in my C program. (It's a library to encode/decode packets from/to a serial bus running with the SNAP-protocol). Unfortunatly there is no source code available, just a C file with function declarations like: long SendData(TXData)Type_TXData *TXData;
3
2006
by: Nick Goloborodko | last post by:
Hi, I've been having a really weird problem with required field validator. Here's the detailed description of the problem: I have originally been developing my web application on Windows XP SP2 under IIS5 with .NET framework V1.1.4322. I have had a couple of RequiredFieldValidator, to ensure that the user enter the username and password on the login form and avoid unnessesary postbacks.
0
1086
by: juxstapose | last post by:
Hello, I have been develop a blocking socket application with threading. The main thread handles connections and inserts them into python's protected queue as jobs for the thread pool to handle. There is not much information on threading.local except that it states that in maintains variable uniqueness among multiple instances of the same thread. I am assuming that it implements some sort of locking functionality under the covers? ...
1
1444
by: Mark Denardo | last post by:
I recently upgraded to VS2005 and converted some projects from 1.1 to 2.0 and am seeing two weird behaviors I can't seem to resolve, and am wondering if they are bugs or something I'm forgetting to do or add. (issue 1) When setting up a panel control with border settings: <asp:Panel Backcolor="BurlyWood" Borderstyle="Ridge" BorderColor="Black" BorderWidth="1px" ... Runat="server" />
2
1531
by: Matt Nordhoff | last post by:
Sebastjan Trepca wrote: Python doesn't like when you read a variable that exists in an outer scope, then try to assign to it in this scope. (When you do "a = b", "b" is processed first. In this case, Python doesn't find a "value" variable in this scope, so it checks the outer scope, and does find it. But then when it gets to the "a = " part... well, I don't know, but it doesn't like it.)
0
10341
Oralloy
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10155
jinu1996
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10095
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,...
0
9954
tracyyun
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...
1
7502
isladogs
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6741
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();...
0
5383
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...
2
3656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2881
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.