exec / execfile namespace problem

Karan Vasudeva karanvasudevaNOkaSPAM at usa.net.invalid
Sat Nov 6 19:55:06 EST 1999


Thanks for responding. I believe I missed out on the real issue here.
You're right, doing a chunk++ like that would be inefficient, but
being new at this, I was kind of looking at getting the whole thing
done first. ok, what i meant was, i'm trying to exec (or execfile)
a script that  does something like this:

> > import httplib
> > h = httplib.HTTP('')
> > h.putrequest('GET', '/favicon.ico')
ok, you can fill in the host here, but that doesn't matter. my problem
is, when i call my script from another script (by doing an exec, thats
what i need to do, you see), the interpreter stops at httplib.py
as it can't find that socket called self.sock . This appears to be a
namespace issue. I just want to know how to do this right.

Both "python cool.py" and exec (and execfile) work absolutely ok
when called interactively. It just doesn't work from another script.

Regards,
Karan.

In article <m3904baoej.fsf at atrus.jesus.cam.ac.uk>, Michael Hudson
<mwh21 at cam.ac.uk> wrote:
> Karan Vasudeva <karanvasudevaNOkaSPAM at usa.net.invalid> writes:
> > Hi,
> >
> > I'm trying to do this:
> > execfile('cool.py')
> >
> > and this:
> >
> > import fileinput
> > chunk = ''
> > for line in fileinput.input('cool.py'):
> >    chunk = chunk + line
> > exec(chunk)
> How does that differ from
> exec open('cool.py').read()
> ? What you have will be really quite inefficient, because
> repeatedly
> executing
>     chunk = chunk + line
> is a quadratic algorithm ... but back to the point.
> >
> > where 'cool.py' is this: (in part)
> > import httplib
> > import time
> > import whrandom
> > h = httplib.HTTP('')
> > h.putrequest('GET', '/favicon.ico')
> Have you tried executing `python cool.py'? The obvious (to me)
> problem
> with the above is that you're not telling httplib about server! I
> think you want
> h = httplib.HTTP("server.domain.tld")
> HTH,
> Michael



* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!





More information about the Python-list mailing list