Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

19 May, 2024: Line wrapping has been changed to be more consistent with Usenet standards.
 If you find that it is broken please let me know here rocksolid.nodes.help


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

SubjectAuthor
o argparse argument post-processingDom Grigonis

1
argparse argument post-processing

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

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=24802&group=comp.lang.python#24802

  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: dom.grigonis@gmail.com (Dom Grigonis)
Newsgroups: comp.lang.python
Subject: argparse argument post-processing
Date: Mon, 27 Nov 2023 13:29:01 +0200
Lines: 38
Message-ID: <mailman.310.1701084545.3828.python-list@python.org>
References: <929736D0-579D-48A1-983F-7271A53BC398@gmail.com>
Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.15\))
Content-Type: text/plain;
charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de ymvToMQJ0Tg8mIHj60uYNwWjINwslGjBshaskz0ppFNQ==
Cancel-Lock: sha1:igFKyU1AU8yBuce2wSrxtpCg4UU= sha256:JdJH2z+9faYShAsmN2lS54ByTDO7g43kXWOPVky/5pw=
Return-Path: <dom.grigonis@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=g4xTuM/g;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '(e.g.': 0.05; 'modules':
0.07; 'string': 0.07; 'module.': 0.09; 'received:mail-
lf1-x134.google.com': 0.09; 'situation,': 0.09; 'skip:` 20': 0.09;
'skip:x 10': 0.09; 'subject:processing': 0.09; 'import': 0.15;
'(after': 0.16; 'all,i': 0.16; 'bash': 0.16; 'paths': 0.16;
'received:apple': 0.16; 'received:smtpclient.apple': 0.16;
'message-id:@gmail.com': 0.18; 'to:addr:python-list': 0.20;
'all,': 0.20; 'input': 0.21; 'maybe': 0.22; 'space': 0.26;
'tried': 0.26; 'output': 0.28; 'ideas': 0.28; 'approach': 0.31;
'---------': 0.32; 'good.': 0.32; 'to:name:python': 0.32; 'but':
0.32; 'someone': 0.34; 'received:google.com': 0.34;
'from:addr:gmail.com': 0.35; 'cases': 0.36; "skip:' 10": 0.37;
'way': 0.38; 'this,': 0.39; 'case.': 0.40; 'stopped': 0.40;
'want': 0.40; 'themselves.': 0.69; 'happens': 0.84;
'subject:post': 0.84; 'insight.': 0.84; 'received:88': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20230601; t=1701084542; x=1701689342; darn=python.org;
h=to:date:message-id:subject:mime-version:from:from:to:cc:subject
:date:message-id:reply-to;
bh=vTOw5dLgcnFzUNXs64Nj8zJHiKmXXXBs+/L2Wsask3w=;
b=g4xTuM/gqjnDWGLBsVC9YyzTG4xvqV4uE1rwIqDmK8dCoVZK6w85ZKMRFB9jFza6F8
ly2t299nnH702XE7LBUDUHrrUri7Py1n7DEjIORxKbtTqP2x76yaKblcYu4v860EFBxW
P8GqmoUShqTLQhLIhrqKfJkMnhxnfSRhqWfo9ggp39FvtYz1VwrRviytq+AyHnuNamhX
dspO4DKrC6z9SLWmKJ/JHHzgJ+aq9aR6KMEiRNlHKDGleogfrj6ySaDejC36KkpiL5MP
+q4gABXTsxnooZGIHsOjbnlsbc0PIk5TzCEV669CwzHlavA14znixuBWSrspdH0e8UKO
4LxQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20230601; t=1701084542; x=1701689342;
h=to:date:message-id:subject:mime-version:from:x-gm-message-state
:from:to:cc:subject:date:message-id:reply-to;
bh=vTOw5dLgcnFzUNXs64Nj8zJHiKmXXXBs+/L2Wsask3w=;
b=t9CIxIo29Iy8u4ynZBN/po0bDCqVjqZnuK2aWN4IeTPzNmYotL9fcCF1MNV4XX6NA2
oKNR/HyJyHsXDe9Or6qJYf3G6t2Sgkt3DVIpWkZoTMf65vjjAwovX0jRdBQHxpZKrTL6
l9PZZngF2zIV8b16Hkl8fvTerCTi2Tsw8sQSCpMITTaedXZM8uX1j5pB0/BerheL0mlo
zWMWgJEQdKis+pOQVJJlsv0aKqMJE4OJXlDEB0cVHaw3OXAWXtp4ydLs+e4Ui1w30g3d
uzPJ/ci3apE0xRGCTjhHi48T9mgUce91OgXIjpZLswXSQXzjtDRv8ZhPTk02AgM2L78a
OFIw==
X-Gm-Message-State: AOJu0Ywa9VLFcocLAJDLC1N9K6tTSvyg03OpDhZ+qLYE4udbFoPwiRJL
H2p+fTumEEcDrcxwyEQZm9lCwsA4EG4=
X-Google-Smtp-Source: AGHT+IG8UC6j1ToUoVafwOYgI6T1cXtjuUfFlB39iM/FSjezt60lH60JRxEZHpmCty0MUGfmbA1bQw==
X-Received: by 2002:a19:8c11:0:b0:50b:a818:f13f with SMTP id
o17-20020a198c11000000b0050ba818f13fmr4555428lfd.64.1701084542265;
Mon, 27 Nov 2023 03:29:02 -0800 (PST)
X-Mailer: Apple Mail (2.3654.120.0.1.15)
X-Content-Filtered-By: Mailman/MimeDel 2.1.39
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: <929736D0-579D-48A1-983F-7271A53BC398@gmail.com>
 by: Dom Grigonis - Mon, 27 Nov 2023 11:29 UTC

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:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('paths', type=lambda x: list(filter(str.strip, x.split(','))))
So far so good. But this is just an example of what sort of solution I am after.

---------

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()`).

I have tried overloading `parse_args` with post-processor arguments, and that seemed fine, but it stopped working when I had sub-parsers, which are defined in different modules and do not call `parse_args` themselves.

Any ideas appreciated,
Regards,
DG


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

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor