Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Class instantiation

Reply
Thread Tools

Class instantiation

 
 
Colin J. Williams
Guest
Posts: n/a
 
      08-23-2006
In the example below, with the disassembly following that, we run into
trouble with the line:
self.connect(fileID, mode= 'r') # open sheet in the read mode

the traceback is:
Traceback (most recent call last):
File "C:\Documents and Settings\cjw\My Documents\OODev\tArray.py",
line 26, in __init__
self.connect(fileID, mode= 'r') # open sheet in the read mode
NameError: global name 'fileID' is not defined

At line 26, location 31, why is LOAD_GLOBAL generated for fileId, when
LOAD_FAST has done the job at locations 0 and 20?

I would appreciate advice.

Colin W.

class arSpread(object):
def __init__(self, fileId= None, ar= None):
if fileId:
if ar is not None:
print fileId
self.connect(fileID, mode= 'r') # open sheet in the read mode
else:
self.connect(fileID, mode= 'w') # open the sheet in the
write mode
if ar is not None:
self.setArray(ar)



[Dbg]>>> dis.disassemble(arSpread.__init__.im_func.func_cod e)
23 0 LOAD_FAST 1 (fileId)
3 JUMP_IF_FALSE 64 (to 70)
6 POP_TOP

24 7 LOAD_FAST 2 (ar)
10 LOAD_GLOBAL 2 (None)
13 COMPARE_OP 9 (is not)
16 JUMP_IF_FALSE 28 (to 47)
19 POP_TOP

25 20 LOAD_FAST 1 (fileId)
23 PRINT_ITEM
24 PRINT_NEWLINE

26 25 LOAD_FAST 0 (self)
28 LOAD_ATTR 4 (connect)
31 LOAD_GLOBAL 5 (fileID)
34 LOAD_CONST 1 ('mode')
37 LOAD_CONST 2 ('r')
40 CALL_FUNCTION 257
43 POP_TOP
44 JUMP_ABSOLUTE 71
>> 47 POP_TOP


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Explicit instantiation of STL vector demands explicit instantiation of all the templates it using internally. krunalbauskar@gmail.com C++ 1 12-25-2006 03:51 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
Set Class Instance to Nothing During Instantiation? Jeff Carver ASP .Net 3 08-25-2004 12:10 PM
JSP problem with classpath and class instantiation ... d wood Java 1 04-15-2004 10:18 PM
Re: Class instantiation puzzle Ike Java 0 06-27-2003 11:02 AM



Advertisments