Question About Command line arguments

2011-06-10 Thread Mark Phillips
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)

Re: Question About Command line arguments

2011-06-10 Thread MRAB
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 =

Re: Question About Command line arguments

2011-06-10 Thread Mark Phillips
On Fri, Jun 10, 2011 at 10:41 AM, MRAB pyt...@mrabarnett.plus.com wrote: 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

Re: Question About Command line arguments

2011-06-10 Thread Kurt Smith
On Fri, Jun 10, 2011 at 12:58 PM, Mark Phillips m...@phillipsmarketing.biz wrote: How do I write my script so it picks up argument from the output of commands that pipe input into my script? def main(): import sys print sys.stdin.read() if __name__ == '__main__': main() $ echo

Re: Question About Command line arguments

2011-06-10 Thread Dennis
On Fri, Jun 10, 2011 at 11:03 AM, Dennis daoden...@gmail.com wrote: On Fri, Jun 10, 2011 at 10:58 AM, Mark Phillips m...@phillipsmarketing.biz wrote: On Fri, Jun 10, 2011 at 10:41 AM, MRAB pyt...@mrabarnett.plus.com wrote: On 10/06/2011 18:21, Mark Phillips wrote: How do I write my script

Re: Question About Command line arguments

2011-06-10 Thread Tim Chase
On 06/10/2011 12:58 PM, Mark Phillips wrote: How do I write my script so it picks up argument from the output of commands that pipe input into my script? You can check if os.isatty(sys.stdin): # -- this check do_stuff_with_the_terminal() else: read_options_from_stdin() -tkc

Re: Question About Command line arguments

2011-06-10 Thread Mark Phillips
On Fri, Jun 10, 2011 at 11:03 AM, Kurt Smith kwmsm...@gmail.com wrote: On Fri, Jun 10, 2011 at 12:58 PM, Mark Phillips m...@phillipsmarketing.biz wrote: How do I write my script so it picks up argument from the output of commands that pipe input into my script? def main(): import sys

Re: Question About Command line arguments

2011-06-10 Thread Robert Kern
On 6/10/11 12:58 PM, Mark Phillips wrote: On Fri, Jun 10, 2011 at 10:41 AM, MRAB pyt...@mrabarnett.plus.com mailto:pyt...@mrabarnett.plus.com wrote: On 10/06/2011 18:21, Mark Phillips wrote: I have a script that processes command line arguments def main(argv=None):

Re: Question About Command line arguments

2011-06-10 Thread Benjamin Kaplan
On Jun 10, 2011 10:26 AM, Mark Phillips m...@phillipsmarketing.biz 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:

Re: Question About Command line arguments

2011-06-10 Thread Dennis
On Fri, Jun 10, 2011 at 11:58 AM, Mark Phillips m...@phillipsmarketing.biz wrote: \ Kurt, How does one write a main method to handle both command line args and stdin args? Here is what I came up with: The one weird thing, the line from above didn't seem to work so I changed it if

Re: Question About Command line arguments

2011-06-10 Thread Dennis
On Fri, Jun 10, 2011 at 1:33 PM, Dennis daoden...@gmail.com wrote: On Fri, Jun 10, 2011 at 11:58 AM, Mark Phillips fred ['alice'] fred Just realized the if/else will have to be changed slightly if we want to output both argv and stdin. -- http://mail.python.org/mailman/listinfo/python-list

Re: Question About Command line arguments

2011-06-10 Thread Benjamin Kaplan
On Fri, Jun 10, 2011 at 11:31 AM, Tim Chase python.l...@tim.thechases.com wrote: On 06/10/2011 12:58 PM, Mark Phillips wrote: How do I write my script so it picks up argument from the output of commands that pipe input into my script? You can check  if os.isatty(sys.stdin):  # -- this

Re: Question About Command line arguments

2011-06-10 Thread Tim Chase
On 06/10/2011 04:00 PM, Benjamin Kaplan wrote: On Fri, Jun 10, 2011 at 11:31 AM, Tim Chase if os.isatty(sys.stdin): #-- this check Any reason for that over sys.stdin.isatty()? my knowledge of os.isatty() existing and my previous lack of knowledge about sys.stdin.isatty() :) -tkc

Re: Question About Command line arguments

2011-06-10 Thread Hans Mulder
On 10/06/11 20:03:44, Kurt Smith wrote: On Fri, Jun 10, 2011 at 12:58 PM, Mark Phillips m...@phillipsmarketing.biz wrote: How do I write my script so it picks up argument from the output of commands that pipe input into my script? def main(): import sys print sys.stdin.read() if