python NameError: global name '__file__' is not defined

前端 未结 12 884
误落风尘
误落风尘 2020-12-02 08:08

When I run this code in python 2.7, I get this error:

Traceback (most recent call last):
File \"C:\\Python26\\Lib\\site-packages\\pyutilib.subprocess-3.5.4\\         


        
12条回答
  •  北荒
    北荒 (楼主)
    2020-12-02 08:17

    Are you using the interactive interpreter? You can use

    sys.argv[0]
    

    You should read: How do I get the path of the current executed file in Python?

提交回复
热议问题