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


Groups > comp.lang.python > #7389

Re: Question About Command line arguments

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python@mrabarnett.plus.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'arguments': 0.05; 'prints': 0.07; 'python': 0.08; '__name__': 0.09; 'arguments,': 0.09; 'arguments.': 0.09; 'fred': 0.09; 'from:addr:python': 0.09; 'none:': 0.09; 'statement.': 0.09; 'def': 0.12; 'wrote:': 0.14; '"__main__":': 0.16; '"echo': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:name:mrab': 0.16; 'input.': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'phillips': 0.16; 'received:84.92': 0.16; 'received:84.92.122': 0.16; 'received:84.92.122.60': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'reply-to:addr:python-list': 0.16; '"python': 0.16; 'argument': 0.16; 'processed': 0.19; 'command': 0.19; 'header:In-Reply-To:1': 0.21; "aren't": 0.22; 'wrote': 0.22; 'received:84': 0.25; 'subject:Question': 0.25; 'script': 0.27; 'problem': 0.28; 'second': 0.30; 'usage': 0.32; 'to:addr:python- list': 0.33; 'there': 0.35; 'header:User-Agent:1': 0.35; 'reply- to:addr:python.org': 0.35; 'run': 0.38; 'subject:: ': 0.38; 'case,': 0.39; 'skip:s 20': 0.39; 'to:addr:python.org': 0.39; 'your': 0.60; 'subject:About': 0.68; 'header:Reply-To:1': 0.72; 'reply-to:no real name:2**0': 0.72; 'subject:line': 0.73
X-IronPort-Anti-Spam-Filtered true
X-IronPort-Anti-Spam-Result AvIGAM9W8k1UXebj/2dsb2JhbABSmBSON3fFKoYjBJV5iwo
Date Fri, 10 Jun 2011 18:41:12 +0100
From MRAB <python@mrabarnett.plus.com>
User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10
MIME-Version 1.0
To python-list@python.org
Subject Re: Question About Command line arguments
References <BANLkTi==QHd+5C=xf+2Re1Mh4V6Hk972hg@mail.gmail.com>
In-Reply-To <BANLkTi==QHd+5C=xf+2Re1Mh4V6Hk972hg@mail.gmail.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
Reply-To python-list@python.org
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.89.1307727680.11593.python-list@python.org> (permalink)
Lines 28
NNTP-Posting-Host 82.94.164.166
X-Trace 1307727680 news.xs4all.nl 49041 [::ffff:82.94.164.166]:50299
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:7389

Show key headers only | View raw


On 10/06/2011 18:21, Mark Phillips wrote:
> I have a script that processes command line arguments
>
> def main(argv=None):
>      syslog.syslog("Sparkler stared processing")
>      if argv is None:
>          argv = sys.argv
>      if len(argv) != 2:
>          syslog.syslog(usage())
>      else:
>          r = parseMsg(sys.argv[1])
>          syslog.syslog(r)
>      return 0
>
> if __name__ == "__main__":
>      sys.exit(main())
>
> When I run "python myscript fred" it works as expected - the argument
> fred is processed in parseMsg as sys.arv[1]
>
> When I run "echo fred | python myscript" the script thinks there are no
> arguments, so it prints out the usage statement.
>
> Is the problem with the echo command, or how I wrote my script?
>
In the second case, there aren't any arguments. The echo command is
writing "fred" to its standard output, which is attached to your
script's standard input.

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


Thread

Re: Question About Command line arguments MRAB <python@mrabarnett.plus.com> - 2011-06-10 18:41 +0100

csiph-web