0

我将我的 python 应用程序捆绑到一个 .AppImage 文件中。现在,当我使用标志运行它时,-h我希望它会按照以下方式打印一些内容:

$ ./mytool.AppImage -h
usage: mytool [-h] [-d DIR] [-f] [-e] [BLA [BLA ...]]
...

但由于 AppImage 捆绑过程的性质,我得到:

$ ./mytool.AppImage -h
usage: AppRun [-h] [-d DIR] [-f] [-e] [BLA [BLA ...]]
...

也就是说,AppRun而不是mytool.

所以我的问题是:

如何强制覆盖应用程序名称,以便无论应用程序如何被调用,它都将始终在使用字符串中打印相同的名称?

4

1 回答 1

2

根据 hpaulj 的评论,这可以通过简单地设置构造函数的prog参数来解决argparse.ArgumentParser

parser = argparse.ArgumentParser(
        prog='mytool',
        description='Some description...'
)
于 2019-07-01T01:47:10.713 回答