Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #7389 > unrolled thread
| Started by | MRAB <python@mrabarnett.plus.com> |
|---|---|
| First post | 2011-06-10 18:41 +0100 |
| Last post | 2011-06-10 18:41 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Question About Command line arguments MRAB <python@mrabarnett.plus.com> - 2011-06-10 18:41 +0100
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2011-06-10 18:41 +0100 |
| Subject | Re: Question About Command line arguments |
| Message-ID | <mailman.89.1307727680.11593.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web