Python argparse:如何处理 MacOSX `-psn` 参数 [英] Python argparse: how to handle MacOSX `-psn` parameter

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

问题描述

MacOSX launchd 将 -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 参数的结构,使用 argparse 解析它而不干扰可能的-p"是不可能的论点(见@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` 参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆