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: 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: References: From: Oscar Benjamin Date: Wed, 15 May 2013 14:00:50 +0100 Subject: Re: Determine actually given command line arguments To: Henry Leyh Content-Type: text/plain; charset=ISO-8859-1 Cc: Python List X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On 15 May 2013 13:52, Henry Leyh wrote: > On 15.05.2013 14:24, Roy Smith wrote: >> >> In article , >> Henry Leyh 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