Difference between __file__ and sys.argv[0]

后端 未结 4 545
面向向阳花
面向向阳花 2020-12-10 23:39

Is there any difference between:

__file__

and

sys.argv[0]

Because both seem to be doing the same thing: they hold

4条回答
  •  醉话见心
    2020-12-11 00:25

    __file__ is the name of the current file, which may be different from the main script if you are inside a module or if you start a script using execfile() rather than by invoking python scriptname.py. __file__ is generally your safer bet.

提交回复
热议问题