Calling class objects

Jp Calderone exarkun at flashmail.com
Sun Mar 5 06:02:25 EST 2000


Gordon McMillan wrote:
> 
> Jp Calderone <exarkun at flashmail.com> wrote:
> 
> > [snip old code]
> >So why doesn't the connectionMade function do what I think it should?
> 
 Oops.  Chalk that up to sloppyness on my part - I didn't want to post
the
200 lines or so of code that the code I posted was supposed to
approximate, 
so I just wrote up what I thought would generate the same problem, but 
didn't test it.  Here's a code segment I actually tested

class Master:
        def startup(self, playerName):
                ## some init stuff, like get call the loadClass function
                ## a few times - this works, printing the results gives
                ## <class base.Player.Player at 80d2800>
                self.playerInitObj = self.loadClass(playerName)

        def connectionMade(self, sock, addr):
                ## Call the constructor with sock and addr
                ## This is where it seems to die - CPU usage jumps
                ## to 100% and the network code stops accepting
connections
                ## - presumably because it is blocking on this call
                self.player = self.playerInitObj(sock, addr)

        def loadClass(self, name):
                mod = __import__(name)
                return eval('mod.' + name)

        def printStuff(self):
            print 'Printing stuff'

if __name__ == '__main__':
    m = Master()
    m.startup('Master')
    obj = m.playerInitObj()
    print obj
    obj.printStuff()


The output of this code is

<Master.Master instance at 80c9c50>
Traceback (innermost last):
  File "Master.py", line 28, in ?
    obj.printStuff()
AttributeError: printStuff


Why is there an AttributeError when I try to call printStuff on
a Master object?


> [snip problems with previously posted code]

-- 
1.79 x 10^24 furlongs per picofortnight - It's not just a good idea, 
			It's the law!
--
 10:48am up 2 days, 16:38, 0 users, load average: 0.01, 0.03, 0.00



More information about the Python-list mailing list