help in execfile function

M

moijes12

Hi

i have 3 python files and i want to execute the files sequentially
using the execfile command.Hence ,i have written the following program


fileList = ["a.py","b.py","c.py"]

for fileName in fileList :
execfile(fileName)

however,when i try running it,the program keeps calling execfile on
a.py and thus an infinite loop is created.I am running this on Windows
XP.

Please suggest a sloution whereby i can use execfile to execute all
files in fileList.Please tell me where in my program i may have gone
wrong.

moijes12
 
S

Steven D'Aprano

Hi

i have 3 python files and i want to execute the files sequentially using
the execfile command.Hence ,i have written the following program


fileList = ["a.py","b.py","c.py"]

for fileName in fileList :
execfile(fileName)

however,when i try running it,the program keeps calling execfile on a.py
and thus an infinite loop is created.I am running this on Windows XP.

Change the line "execfile(fileName)" to "print fileName" and you may
discover that the problem isn't with execfile but with your code.

Then read about modules and import, and you may discover that there is a
better way than execfile.


(I wish that eval, exec and execfile were hidden in a module where noobs
couldn't trip over them and decide they are the answer to every problem.
Sigh.)

Please suggest a sloution whereby i can use execfile to execute all
files in fileList.Please tell me where in my program i may have gone
wrong.

Looking into my crystal ball, I'm guessing that file a.py contains a line
that says "execfile('a.py')".
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top