help in execfile function

Discussion in 'Python' started by moijes12, Sep 4, 2008.

  1. moijes12

    moijes12 Guest

    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
    moijes12, Sep 4, 2008
    #1
    1. Advertising

  2. On Thu, 04 Sep 2008 05:03:57 -0700, moijes12 wrote:

    > 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')".

    --
    Steven
    Steven D'Aprano, Sep 4, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jonathan
    Replies:
    2
    Views:
    528
    Steven Taschuk
    Aug 10, 2003
  2. Enrique

    execfile return values

    Enrique, Oct 3, 2003, in forum: Python
    Replies:
    2
    Views:
    1,531
    Dennis Lee Bieber
    Oct 3, 2003
  3. Roman Suzi

    PEP263 and execfile()

    Roman Suzi, Nov 17, 2003, in forum: Python
    Replies:
    4
    Views:
    292
    Martin v. =?iso-8859-15?q?L=F6wis?=
    Nov 18, 2003
  4. Replies:
    1
    Views:
    413
  5. Dave Westerman

    execfile and function call

    Dave Westerman, Sep 24, 2007, in forum: Python
    Replies:
    2
    Views:
    242
    Gabriel Genellina
    Sep 25, 2007
Loading...

Share This Page