473,396 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

UnboundLocalError

15
I am stuck at the a small code as the following:

This is module main, the main entry of the application :
Expand|Select|Wrap|Line Numbers
  1. from irc_log_mod import *
  2. from irc_chatter_mod import *
  3. from inspect import *
  4. from irc_global_mod import *
  5.  
  6. def main():
  7.     try:
  8.             curFrame = currentframe()
  9.             writeLog(LOG,
  10.                      curFrame.f_code.co_filename,
  11.                      "",
  12.                      "main()",
  13.                      curFrame.f_lineno,
  14.                      DBG_LEVEL_ONE,
  15.                      "FUNCTION ENTRY")
  16.     finally:
  17.             del curFrame
  18.  
  19.     # problem comes in this line
  20.     chatter = cchatter("nickname", "username", "fullname", 1)
  21.  
  22.     # ... rest of the code .....
  23.  
The class cchatter is coded in a module called irc_chatter_mod; and its constructor looks like this :
Expand|Select|Wrap|Line Numbers
  1. def __init__(self, nickname, username, fullname, flag):
  2.  
  3.         # cchatter::__init__ : BEGIN
  4.  
  5.                 # FUNCTION ENTRY
  6.  
  7.                 try:
  8.                         curFrame = currentframe()
  9.                         writeLog(LOG,
  10.                                  curFrame.f_code.co_filename,
  11.                                  "cchatter",
  12.                                  "__init__",
  13.                                  curFrame.f_lineno,
  14.                                  DBG_LEVEL_THREE,
  15.                                  "FUNCTION ENTRY")
  16.                 finally:
  17.                         # The problem is here
  18.                         del curFrame
  19.  
  20.               # ...rest of the codes......
  21.  
  22.  
Problem :
The compiler outputs :
File "C:\public\projects\py\AmeL\irc_chatter_mod_unit_t est.py", line 41, in <module>
main()
File "C:\public\projects\py\AmeL\irc_chatter_mod_unit_t est.py", line 18, in main
chatter = cchatter("nickname", "username", "fullname", 1)
File "C:\public\projects\py\AmeL\irc_chatter_mod.py ", line 55, in __init__
del curFrame
UnboundLocalError: local variable 'curFrame' referenced before assignment


From my point of view, this error message should be thrown when a variable is referenced, or used, before it is assigned by any value. I found nothing go wrong with my code.
Could you guys please help me ?
Jun 5 '09 #1
1 1401
AmeL
15
Oh god
The problem is at last solved, I forgot to import a module named inspect :)
Jun 5 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
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...
6
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...
2
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...
8
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:...
15
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...
9
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:
2
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... ...
8
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):...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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...
0
agi2029
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,...

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.