cmdline args to a piped python prog

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • leo

    cmdline args to a piped python prog

    hi there

    a python file can evaluate cmdline arguments like

    python myprog.py arg1 arg2 arg3...

    when i feed python with my program via terminal input like

    cat myprog.py | python

    how can i then specifiy the cmdline arguments arg1 arg2 arg3...?

    thanks a lot, leo

    ps: wondering why i ask? -- emacs calls python code from abuffer always in
    the latter way.



  • Piet van Oostrum

    #2
    Re: cmdline args to a piped python prog

    >>>>> "leo" <halloleo@noosp aam.myrealbox.c om> (L) wrote:

    L> hi there
    L> a python file can evaluate cmdline arguments like

    L> python myprog.py arg1 arg2 arg3...

    L> when i feed python with my program via terminal input like

    L> cat myprog.py | python

    L> how can i then specifiy the cmdline arguments arg1 arg2 arg3...?

    You could say cat myprog.py | python - arg1 arg2 arg3
    Then sys.argv[1:] contains the arguments.

    By the way cat myprog.py | python * is equivalent to python * < myprog.py
    No need for cat.
    --
    Piet van Oostrum <piet@cs.uu.n l>
    URL: http://www.cs.uu.nl/~piet [PGP]
    Private email: P.van.Oostrum@h ccnet.nl

    Comment

    • leo

      #3
      ta (was Re: cmdline args to a piped python prog)

      thanks a lot, piet.

      leo

      "Piet van Oostrum" <piet@cs.uu.n l> wrote in message
      news:wzvfld3rl2 .fsf@ordesa.cs. uu.nl...[color=blue][color=green][color=darkred]
      > >>>>> "leo" <halloleo@noosp aam.myrealbox.c om> (L) wrote:[/color][/color]
      >
      > L> hi there
      > L> a python file can evaluate cmdline arguments like
      >
      > L> python myprog.py arg1 arg2 arg3...
      >
      > L> when i feed python with my program via terminal input like
      >
      > L> cat myprog.py | python
      >
      > L> how can i then specifiy the cmdline arguments arg1 arg2 arg3...?
      >
      > You could say cat myprog.py | python - arg1 arg2 arg3
      > Then sys.argv[1:] contains the arguments.
      >
      > By the way cat myprog.py | python * is equivalent to python * < myprog.py
      > No need for cat.
      > --
      > Piet van Oostrum <piet@cs.uu.n l>
      > URL: http://www.cs.uu.nl/~piet [PGP]
      > Private email: P.van.Oostrum@h ccnet.nl[/color]


      Comment

      Working...