By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,089 Members | 2,359 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,089 IT Pros & Developers. It's quick & easy.

UnboundLocalError

P: 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
Share this Question
Share on Google+
1 Reply


P: 15
Oh god
The problem is at last solved, I forgot to import a module named inspect :)
Jun 5 '09 #2

Post your reply

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