Search code examples
pythonmacosargparselaunchd

Python argparse: how to handle MacOSX `-psn` parameter


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?

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


Solution

  • 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.