Get name of current script in Python

前端 未结 18 2389
北荒
北荒 2020-11-28 00:54

I\'m trying to get the name of the Python script that is currently running.

I have a script called foo.py and I\'d like to do something like this in ord

18条回答
  •  日久生厌
    2020-11-28 01:07

    If you're doing an unusual import (e.g., it's an options file), try:

    import inspect
    print (inspect.getfile(inspect.currentframe()))
    

    Note that this will return the absolute path to the file.

提交回复
热议问题