How to retrieve a module's path?

后端 未结 20 1748
无人及你
无人及你 2020-11-22 05:34

I want to detect whether module has changed. Now, using inotify is simple, you just need to know the directory you want to get notifications from.

How do I retrieve

20条回答
  •  别跟我提以往
    2020-11-22 06:00

    If you would like to know absolute path from your script you can use Path object:

    from pathlib import Path
    
    print(Path().absolute())
    print(Path().resolve('.'))
    print(Path().cwd())
    

    cwd() method

    Return a new path object representing the current directory (as returned by os.getcwd())

    resolve() method

    Make the path absolute, resolving any symlinks. A new path object is returned:

提交回复
热议问题