[Python-Dev] exec documentation

Glenn Linderman v+python at g.nevcal.com
Sat Jan 10 01:26:46 CET 2009

On approximately 1/9/2009 3:40 PM, came the following characters from 
the keyboard of Terry Reedy:
> Glenn Linderman wrote:
>> in 2.6 and before execfile is listed in builtin functions, and is not 
>> marked deprecated, and exec is in the simple statements, and is not 
>> marked deprecated.
> Because they are not going away in 2.7.

Ah, that's the missing piece!  I keep thinking 2.5, 2.6, 3.0, and 
forgetting that someone might make a 2.7 :)  I bet I wasn't the first 
one to be confused by this, nor am I likely to be the last.

>> in 3.0 execfile is not listed in builtin functions, exec is.  exec is 
>> not listed in simple statements.
> All as appropriate.

Sure, given a 2.7

>> I guess this is an intended 3.0 change, but is this the proper way to 
>> document it?
> This is really a python-list/c.l.p question:  Anyway... What's new 3.0: 
> "exec() is no longer a keyword; it remains as a function."..."Removed 
> execfile(). Instead of execfile(fn) use exec(open(fn).read()). " ...Yes.
>> What I was really trying to figure out is how I could specify the 
>> encoding of a file to be execfile'd in 2.6... but didn't find it so 
>> thought I'd try 3.0 to see if it would assume UTF-8, but had forgotten 
>> execfile doesn't exist in 3.0 (if I knew it; I'm new here).
> Ditto - how to use current 3.0, not how to develop 3.0.1/3.1.  Anyway, 
> specify encoding in the open function.

execfile( "file.py" )

Where is the open function?

I have it working under 3.0, not sure how to specify the encoding for 
2.6, though, and this question is now off-topic for Python-Dev.

Glenn -- http://nevcal.com/
A protocol is complete when there is nothing left to remove.
-- Stuart Cheshire, Apple Computer, regarding Zero Configuration Networking

More information about the Python-Dev mailing list