runtime code loading

David Fisher python at rose164.wuh.wustl.edu
Thu Mar 2 04:54:46 EST 2000


Hi Jp,
Your post is a little hard to answer.  It would help to know what the
program is supposed to do, what the line of code is supposed to do, what
platform and version you are running on.  Including a small piece of working
code that exibits the problem, instead of code fragments would help also.
That said, it looks like you want to create an instance of the class Player
and store it in self.connections[addr]. It would also help to know why you
are doing it with open, read, compile, etc.  Unless you have a good reason
not to, I would sugest you use the standard import function to load code
from a file.
Post with some more info, and we'll try again.
david

----- Original Message -----
From: "Jp Calderone" <exarkun at mudprovider.com>
Newsgroups: comp.lang.python
To: <python-list at python.org>
Sent: Wednesday, March 01, 2000 12:51 PM
Subject: runtime code loading


> (First, I'm a realtive newbie to Python, so if this is dumb, please excuse
> me)  I've got the following code and I can't figure out why it freezes at
> the marked line:
>
>     def connectionMade(self, sock, addr):
>         print 'Getting pObj...',
>         pObj = self.bootstrapObjects['Player']
>         print 'Done\nGetting lObj...',
>         lObj = self.bootstrapObjects['LoginParser']
>         print 'Done\nCreating player...'
>         self.connections[addr] = pObj(lObj, sock, addr) # Freezes here
>         print 'Done'
>
>
> pObj and lObj are loaded with this code:
>
> def load(name):
>     infile = open('../lib/code/' + name, 'r')
>     source = infile.readlines()
>     result = compile(string.join(source, '\n'), '../lib/code/' + name,
> 'single'
>     return result
>
> and the code files contain:"
>
> class Player:
>
>         socket = None
>         address = None
>
>         def __init__(self, socket, addr):
>                 print 'Player init'
>                 self.socket = socket
>                 self.address = addr
>
>         def hasData(self):
>                 return self.socket.ready()
>
>         def parse(self):
>                 if not self.hasData():
>                         return
>                 else:
>                         pass
>
> class LoginParser:
>
>         state = -1
>
>         def __init__(self):
>                 self.state = 0
>
>
> Anything obvious that I'm doing wrong (or am I approhacing this from
> completely the wrong angle?)
>
> Thanks in advance
> --
> http://www.python.org/mailman/listinfo/python-list





More information about the Python-list mailing list