本文介绍了Python argparse:如何处理MacOSX的-psn参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MacOSX将-psn...参数传递给应用程序.我该如何告诉argparse如何解析参数?它基本上是-psn_([0-9]+)_([0-9]+),但是如果它只解析-psn(\S*),我很好.可能吗?

MacOSX launchd passes the -psn... parameter to applications. How can I tell argparse how to parse the parameter? It's basically -psn_([0-9]+)_([0-9]+) but I'm fine if it just parses -psn(\S*). Is that possible at all?

(请参见此处,获取有关进程序列号(PSN)的一些文档.是我关于如何处理参数的问题.)

(See here for some documentation about the Process Serial Number (PSN). And here is my question about what to do with the parameter.)

推荐答案

查看 psn 参数的结构,在不干扰可能的"-p"的情况下,无法通过argparse对其进行解析.参数(请参阅@hpaulj的答案).因此,我建议使用部分解析,然后提取从余数列表中获取.

Looking at the structure of the psn argument, it's not possible to parse it with argparse without interfering with a possible "-p" argument (see @hpaulj's answer). So, I'd recommend to use partial parsing, and extract it from the list of remainders.

这篇关于Python argparse:如何处理MacOSX的-psn参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 17:46