找到你要的答案

Q:Way to get current directory in global python script

Q:的方式来获得全球的Python脚本当前目录

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

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

有什么办法能让工作目录时我打电话给全球的Python脚本,通过entry_points在它创造的吗?

doge.py:

import sys

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

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'],
    }
)

所以我想把我从那里调用这个脚本目录通过“总督”命令

answer1: 回答1:

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

 import os
 os.getcwd()

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

 import os
 os.getcwd()
python  setuptools