在全局python脚本中获取当前目录的方法

时间:2022-10-14 23:42:59

Is there any way to get working directory when I call global python script, created by entry_points in setuptools?

当我调用由setuptools中的entry_points创建的全局python脚本时,有没有办法获得工作目录?

doge.py:

import sys

def da():
    print("Doge greets you!\n")
    print(sys.argv)

setup.py:

from setuptools import setup
setup(
    name='doge-script',
    version='0.1',
    description='Bla',
    author='Me',
    author_email='',
    url='',
    scripts=["doge.py"],
    entry_points={
        'console_scripts': ['rundoge = doge:da'],
    }
)

So I would like to get directory whence I call this script via "doge" command

所以我想通过“doge”命令调用这个脚本的目录

1 个解决方案

#1


I believe this will help you out. See https://docs.python.org/2/library/os.html

我相信这会帮助你。请参阅https://docs.python.org/2/library/os.html

 import os
 os.getcwd()

#1


I believe this will help you out. See https://docs.python.org/2/library/os.html

我相信这会帮助你。请参阅https://docs.python.org/2/library/os.html

 import os
 os.getcwd()