exec / execfile namespace problem

Michael Hudson mwh21 at cam.ac.uk
Sat Nov 6 05:46:12 EST 1999


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




More information about the Python-list mailing list