NameError: name 'execfile' is not defined

H

Henrik Bechmann

Newbie issue:

I downloaded http://www.python.org/download/releases/3.0.1/ (windows
insaller), opened the interpreter, wrote a print "Hello World" program
in helloworld.py, and in the interpreter typed

execfile("helloworld.py")

Got back

NameError: name 'execfile' is not defined

(following tutorial in David Beazley's Python Essential Reference).

Is execfile not supported in 3?

Thanks,

- Henrik
 
G

Gary Herron

Henrik said:
Newbie issue:

I downloaded http://www.python.org/download/releases/3.0.1/ (windows
insaller), opened the interpreter, wrote a print "Hello World" program
in helloworld.py, and in the interpreter typed

execfile("helloworld.py")

Got back

NameError: name 'execfile' is not defined

(following tutorial in David Beazley's Python Essential Reference).

Is execfile not supported in 3?

That's correct.

From http://docs.python.org/dev/3.0/whatsnew/3.0.html you can find this
line:

Removed execfile(). Instead of execfile(fn) use exec(open(fn).read()).

Gary Herron
 
H

Henrik Bechmann

That's correct.

 Fromhttp://docs.python.org/dev/3.0/whatsnew/3.0.htmlyou can find this
line:

    Removed execfile().   Instead of execfile(fn) use exec(open(fn)..read()).

Gary Herron

Excellent. Thanks very much!

- Henrik
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top