How to retrieve a module's path?

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

    Here is a quick bash script in case it's useful to anyone. I just want to be able to set an environment variable so that I can pushd to the code.

    #!/bin/bash
    module=${1:?"I need a module name"}
    
    python << EOI
    import $module
    import os
    print os.path.dirname($module.__file__)
    EOI
    

    Shell example:

    [root@sri-4625-0004 ~]# export LXML=$(get_python_path.sh lxml)
    [root@sri-4625-0004 ~]# echo $LXML
    /usr/lib64/python2.7/site-packages/lxml
    [root@sri-4625-0004 ~]#
    

提交回复
热议问题