How to retrieve a module's path?

后端 未结 20 1744
无人及你
无人及你 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:17

    There is inspect module in python.

    Official documentation

    The inspect module provides several useful functions to help get information about live objects such as modules, classes, methods, functions, tracebacks, frame objects, and code objects. For example, it can help you examine the contents of a class, retrieve the source code of a method, extract and format the argument list for a function, or get all the information you need to display a detailed traceback.

    Example:

    >>> import os
    >>> import inspect
    >>> inspect.getfile(os)
    '/usr/lib64/python2.7/os.pyc'
    >>> inspect.getfile(inspect)
    '/usr/lib64/python2.7/inspect.pyc'
    >>> os.path.dirname(inspect.getfile(inspect))
    '/usr/lib64/python2.7'
    

提交回复
热议问题