Re: How to use "while" within the command in -c option of python?

Discussion in 'Python' started by Ned Deily, Oct 13, 2012.

  1. Ned Deily

    Ned Deily Guest

    In article
    <>,
    Herman <> wrote:
    > I was just trying to do in a shell to quickly monitor a file. Imagine
    > instead of printing hello, it is "os.system("cat somefile")", etc.
    > Look like it works if i press an enter after the "import xxx". Thanks.


    If you are using a POSIX-compatible shell, the canonical approach for
    use cases like this is to use a "here document", for example:

    python - <<EOF
    import os
    while True:
    print('hello')
    EOF

    The "-" tells the Python interpreter to read from stdin. The shell
    supplies the lines between the <<EOF and the matching EOF as stdin.

    http://en.wikipedia.org/wiki/Here_document

    --
    Ned Deily,
     
    Ned Deily, Oct 13, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shawn Minisall

    while within while

    Shawn Minisall, Oct 27, 2007, in forum: Python
    Replies:
    11
    Views:
    529
  2. Herman
    Replies:
    0
    Views:
    173
    Herman
    Oct 12, 2012
  3. Etienne Robillard
    Replies:
    11
    Views:
    295
    Chris Angelico
    Oct 13, 2012
  4. Dave Angel
    Replies:
    0
    Views:
    198
    Dave Angel
    Oct 13, 2012
  5. Herman
    Replies:
    0
    Views:
    230
    Herman
    Oct 13, 2012
Loading...

Share This Page