Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #45340

Re: Determine actually given command line arguments

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <oscar.j.benjamin@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.011
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'defaults': 0.07; 'sys': 0.07; 'arguments': 0.09; 'namespace': 0.09; 'parsing': 0.09; 'subject:command': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'wrote': 0.14; "'bar']": 0.16; 'cc:name:python list': 0.16; 'henry': 0.16; 'optional': 0.16; 'roy': 0.16; 'thanks,': 0.17; 'wrote:': 0.18; 'command': 0.22; '>>>': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'cc:2**0': 0.24; 'sort': 0.25; 'options': 0.25; 'compare': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'sets': 0.30; 'message- id:@mail.gmail.com': 0.30; 'posting': 0.31; 'changed.': 0.31; 'stuff': 0.32; 'maybe': 0.34; "i'd": 0.34; 'could': 0.34; 'received:209.85': 0.35; 'created': 0.35; 'received:209.85.220': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'really': 0.36; 'i.e.': 0.36; 'received:209': 0.37; 'e.g.': 0.38; 'does': 0.39; 'simple': 0.61; "you're": 0.61; 'first': 0.61; 'kind': 0.63; 'determine': 0.67; 'line,': 0.68; 'smith': 0.68; 'hoping': 0.75; 'article': 0.77; 'oscar': 0.84; 'imagine': 0.93; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=LZIDv7Ro8jn5Y3YTejbR2kNxav0md9sebdG+qBkQTbw=; b=dAdbT3mxGnKk0dQTBanLav2+4hKgGwQPBWo0JGy1C02RY4Z3oDbnnErZCYizjW4b/J V6ozyu/0yZLcjGaYv1R6pXQ+YN9sD/7S2zpm9Qdp7f03DnCjRXtjgAv9paGlWcO9TLVP IYJHm11cZLn2Ld74v/MfEUQFW6apb6++Gd027GXDCUdZK1iEIZMBaAie8nEYJuLOCqUg 15Pr5KINAmOpN78x+QKfmLweSp091pW8yce0sQWj7nvcqM/6IXInr3Lxirbq4zZcx4Lu 8YfrGeugLOMD5Zn2qjsrDfAdVwfIRamGNfETCdWLBm0Lyu0wMj687A3eW4M6GtU0QGMo bdgQ==
X-Received by 10.58.180.196 with SMTP id dq4mr24814431vec.10.1368622870300; Wed, 15 May 2013 06:01:10 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <kn00fb$8kc$1@gwdu112.gwdg.de>
References <kmva9j$1hbk$1@gwdu112.gwdg.de> <roy-C8F8F4.08245415052013@news.panix.com> <kn00fb$8kc$1@gwdu112.gwdg.de>
From Oscar Benjamin <oscar.j.benjamin@gmail.com>
Date Wed, 15 May 2013 14:00:50 +0100
Subject Re: Determine actually given command line arguments
To Henry Leyh <henry.leyh@ipp.mpg.de>
Content-Type text/plain; charset=ISO-8859-1
Cc Python List <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1697.1368622878.3114.python-list@python.org> (permalink)
Lines 35
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1368622878 news.xs4all.nl 15976 [2001:888:2000:d::a6]:60386
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:45340

Show key headers only | View raw


On 15 May 2013 13:52, Henry Leyh <henry.leyh@ipp.mpg.de> wrote:
> On 15.05.2013 14:24, Roy Smith wrote:
>>
>> In article <kmva9j$1hbk$1@gwdu112.gwdg.de>,
>>   Henry Leyh <henry.leyh@ipp.mpg.de> wrote:
>>
>>> Is there a simple way to determine which
>>> command line arguments were actually given on the commandline, i.e. does
>>> argparse.ArgumentParser() know which of its namespace members were
>>> actually hit during parse_args().
>>
>>
>> I think what you're looking for is sys.argv:
>>
>> $ cat argv.py
>> import sys
>> print sys.argv
>>
>> $ python argv.py foo bar
>> ['argv.py', 'foo', 'bar']
>
> Thanks, but as I wrote in my first posting I am aware of sys.argv and was
> hoping to _avoid_ using it because I'd then have to kind of re-implement a
> lot of the stuff already there in argparse, e.g. parsing sys.argv for
> short/long options, flag/parameter options etc.
>
> I was thinking of maybe some sort of flag that argparse sets on those
> optional arguments created with add_argument() that are really given on the
> command line, i.e. those that it stumbles upon them during parse_args().

I don't know about that but I imagine that you could compare values
with their defaults to see which have been changed.


Oscar

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Determine actually given command line arguments Henry Leyh <henry.leyh@ipp.mpg.de> - 2013-05-15 08:34 +0200
  Re: Determine actually given command line arguments "Colin J. Williams" <cjw@ncf.ca> - 2013-05-15 08:03 -0400
    Re: Determine actually given command line arguments Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-05-15 15:51 +0300
  Re: Determine actually given command line arguments Roy Smith <roy@panix.com> - 2013-05-15 08:24 -0400
    Re: Determine actually given command line arguments Dave Angel <davea@davea.name> - 2013-05-15 08:51 -0400
    Re: Determine actually given command line arguments Henry Leyh <henry.leyh@ipp.mpg.de> - 2013-05-15 14:52 +0200
      Re: Determine actually given command line arguments Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-05-15 14:00 +0100
        Re: Determine actually given command line arguments Henry Leyh <henry.leyh@ipp.mpg.de> - 2013-05-15 15:50 +0200
          Re: Determine actually given command line arguments Skip Montanaro <skip@pobox.com> - 2013-05-15 09:08 -0500
            Re: Determine actually given command line arguments Henry Leyh <henry.leyh@ipp.mpg.de> - 2013-05-15 16:39 +0200
              Re: Determine actually given command line arguments Skip Montanaro <skip@pobox.com> - 2013-05-15 09:51 -0500
          Re: Determine actually given command line arguments Wayne Werner <wayne@waynewerner.com> - 2013-05-15 09:16 -0500
      Re: Determine actually given command line arguments roy@panix.com (Roy Smith) - 2013-05-15 11:29 -0400
        Re: Determine actually given command line arguments Henry Leyh <henry.leyh@ipp.mpg.de> - 2013-05-16 07:43 +0200
          Re: Determine actually given command line arguments Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-05-16 09:08 +0300
            Re: Determine actually given command line arguments Henry Leyh <henry.leyh@ipp.mpg.de> - 2013-05-16 09:29 +0200

csiph-web