Class instantiation

C

Colin J. Williams

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_code)
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top