Class instantiation

Discussion in 'Python' started by Colin J. Williams, Aug 23, 2006.

  1. 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
    >> 47 POP_TOP
    Colin J. Williams, Aug 23, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeff Carver
    Replies:
    3
    Views:
    419
    Jeff Carver
    Aug 25, 2004
  2. Ike
    Replies:
    0
    Views:
    1,317
  3. d wood
    Replies:
    1
    Views:
    544
    Christophe Vanfleteren
    Apr 15, 2004
  4. E11
    Replies:
    1
    Views:
    4,720
    Thomas Weidenfeller
    Oct 12, 2005
  5. Replies:
    1
    Views:
    562
    Salt_Peter
    Dec 25, 2006
Loading...

Share This Page