Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Live free or die.


devel / comp.lang.python / Re: argparse argument post-processing

SubjectAuthor
o Re: argparse argument post-processingChris Angelico

1
Re: argparse argument post-processing

<mailman.311.1701089964.3828.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=24561&group=comp.lang.python#24561

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!not-for-mail
From: ros...@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: argparse argument post-processing
Date: Mon, 27 Nov 2023 23:59:10 +1100
Lines: 34
Message-ID: <mailman.311.1701089964.3828.python-list@python.org>
References: <929736D0-579D-48A1-983F-7271A53BC398@gmail.com>
<CAPTjJmrqo12DUOggERUpWtUwTScQFa_39ovodyLZE49bKrHGZg@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de /aSn7kAKqI+ADtp2kfOu1Q5+akjuefGSJmJcfyV+525A==
Cancel-Lock: sha1:+2jXjt1mFXscwmdDwz8ifG+2YgY= sha256:0c8yqPRT22HS3MDUof7FuNyhmpY6fqBwmCcYuUFdTpc=
Return-Path: <rosuav@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=ZuUrOQ+P;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.002
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '(e.g.': 0.05; '2023':
0.07; 'joining': 0.07; 'string': 0.07; 'module.': 0.09;
'situation,': 0.09; 'skip:` 20': 0.09; 'subject:processing': 0.09;
'import': 0.15; '(after': 0.16; 'arguments': 0.16; 'bash': 0.16;
'chrisa': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris
angelico': 0.16; 'parsing': 0.16; 'paths': 0.16; 'received:mail-
lj1-x235.google.com': 0.16; 'wrote:': 0.16; 'to:addr:python-list':
0.20; 'all,': 0.20; 'input': 0.21; 'maybe': 0.22; 'examples':
0.25; 'space': 0.26; 'expect': 0.28; 'output': 0.28; 'approach':
0.31; 'python-list': 0.32; 'to:name:python': 0.32; 'message-
id:@mail.gmail.com': 0.32; 'but': 0.32; "i'm": 0.33; 'someone':
0.34; 'header:In-Reply-To:1': 0.34; 'received:google.com': 0.34;
'from:addr:gmail.com': 0.35; 'cases': 0.36; 'mon,': 0.36; "skip:'
10": 0.37; 'way': 0.38; 'single': 0.39; 'this,': 0.39; 'case.':
0.40; 'otherwise,': 0.40; 'want': 0.40; 'here': 0.62; 'your':
0.64; 'that,': 0.67; 'see,': 0.76; 'happens': 0.84;
'subject:post': 0.84; 'dom': 0.84; 'insight.': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20230601; t=1701089962; x=1701694762; darn=python.org;
h=content-transfer-encoding:to:subject:message-id:date:from
:in-reply-to:references:mime-version:from:to:cc:subject:date
:message-id:reply-to;
bh=mFW99MVSqdRe7beqrQjt6JRGMQAjpg7JStS0xvbdYSE=;
b=ZuUrOQ+PzOZ3ZMto4y2B1UJwVhS4z/Z4D4HO086Sg1hJgFA/gtjTUqhj8T84/w2NI4
eVNQrSGorrK1FwCY3sbfdoeyEVasplnMQDjfQhWOhE7ZEA4fzLxJdXrXQ3bI9y8Qtd0I
/KK54h4QB9f2kYFfudSwctArebpdv9U3iJlHa5SAkDjLwkPbrQP3OT7v12rhLS1KtJQf
cpju3HG/f4y9kH/e2l49y2f4cz7e6/GCocOKrbGY/vuRyr4Mb558srRbEIrUiuEn//KB
jVZ0FhHRmwtDaN1YCg8W28HnSlicPEb0+5S59l5+ae+n58wgCIXRDkZYOj1Ys/yQ3Sk6
zDug==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20230601; t=1701089962; x=1701694762;
h=content-transfer-encoding:to:subject:message-id:date:from
:in-reply-to:references:mime-version:x-gm-message-state:from:to:cc
:subject:date:message-id:reply-to;
bh=mFW99MVSqdRe7beqrQjt6JRGMQAjpg7JStS0xvbdYSE=;
b=XjH/eez8q2xhrbaHR6BtBRY7lgi53WE6U5GT/vHNbP5r5E8Npi36jyYP09inC602mv
oq3BWCzk/FY4JBrqQ21HqreKcH4M7GvCWLOP9RQVcgmqGzPkPLE73IvskwDNo+/yxiaF
XD+QQVqTgozIuGAe/lotNouizDKWTaclEmmG55nWWoK1gv/duErUuqxZ7+JRJ6pMPXEt
fQtw6r1CK/uQ/4Fmug/CtyqnTeyCrJoTILDmch9g02IHQIZRFjfZ/HDdjTl13Z+BkRHR
JPggAgUctAQeKi9RnP0dCICQblG9skn8mcGl4H0HQvrfru8/0tRLGv4pwkTrTY60YEdh
7XAQ==
X-Gm-Message-State: AOJu0Yy32si2nlp/IEk8xhjDKqAqefa3ib/iVFL7uYOlRPHzrTJMN3an
2PuTjT2BfKq7lW20q1kRJS4H4kIn2R0OAP/LQ71VWVXw
X-Google-Smtp-Source: AGHT+IGrqihSF2q9lOqDPfR7L+UpAXGpJOh6qLPPlCT/g2DsWBf/8UXkqRmLDM3bR06Ccs7P+Nl0+rd6+HhzTcHw47A=
X-Received: by 2002:a2e:b549:0:b0:2c9:9904:59ac with SMTP id
a9-20020a2eb549000000b002c9990459acmr3837380ljn.27.1701089961749; Mon, 27 Nov
2023 04:59:21 -0800 (PST)
In-Reply-To: <929736D0-579D-48A1-983F-7271A53BC398@gmail.com>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <CAPTjJmrqo12DUOggERUpWtUwTScQFa_39ovodyLZE49bKrHGZg@mail.gmail.com>
X-Mailman-Original-References: <929736D0-579D-48A1-983F-7271A53BC398@gmail.com>
 by: Chris Angelico - Mon, 27 Nov 2023 12:59 UTC

On Mon, 27 Nov 2023 at 22:31, Dom Grigonis via Python-list
<python-list@python.org> wrote:
>
> Hi all,
>
> I have a situation, maybe someone can give some insight.
>
> Say I want to have input which is comma separated array (e.g. paths='path1,path2,path3') and convert it to the desired output - list:

This is a single argument.

> Now the second case. I want input to be space separated array - bash array. And I want space-separated string returned. My current approach is:
> import argparse
> parser = argparse.ArgumentParser()
> parser.add_argument('paths', nargs='+')
> args = parser.parse_args()
> paths = ' '.join(args.paths)
> But what I am looking for is a way to do this, which is intrinsic to `argparse` module. Reason being I have a fair amount of such cases and I don’t want to do post-processing, where post-post-processing happens (after `parser.parse_args()`).
>

This is parsing multiple arguments.

If you want it space-separated, you can do that, just as a single
argument. Otherwise, what you're doing is taking multiple arguments
and joining them. I'm not sure what you expect to see, but your
examples here pretty clearly show that you are taking multiple
arguments, and joining them with spaces.

ChrisA

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor