What is an alternative to execfile in Python 3?

前端 未结 12 1777
滥情空心
滥情空心 2020-11-22 02:33

It seems they canceled in Python 3 all the easy way to quickly load a script by removing execfile()

Is there an obvious alternative I\'m missing?

12条回答
  •  名媛妹妹
    2020-11-22 03:01

    I'm just a newbie here so maybe it's pure luck if I found this :

    After trying to run a script from the interpreter prompt >>> with the command

        execfile('filename.py')
    

    for which I got a "NameError: name 'execfile' is not defined" I tried a very basic

        import filename
    

    it worked well :-)

    I hope this can be helpful and thank you all for the great hints, examples and all those masterly commented pieces of code that are a great inspiration for newcomers !

    I use Ubuntu 16.014 LTS x64. Python 3.5.2 (default, Nov 17 2016, 17:05:23) [GCC 5.4.0 20160609] on linux

提交回复
热议问题