unbuffered python output

$ python -u script.py
You have a python script that slowly prints output, you want to pipe the output to grep or tee, and you are impatient and want to watch the results right away. Rather than modify your script (making it slightly less efficient), use the -u option to have the output unbuffered.

2
2010-05-20 17:53:47

These Might Interest You

  • Sometimes the question comes up: How to get unbuffered tcpdump output into the next program in the pipe? i.e. if your OS forces you to wait for the buffer to fill before the next program sees any of the output If you use -Uw- then you can't use -A (or -X or -XX) at the same time. When the question comes up, I've never seen anyone suggest this simple solution: chaining 2 tcpdump instances.


    1
    tcp(){ tcpdump -nUs0 -w- -iinterface $1|tcpdump -n${2-A}r- ;} usage: tcp '[primitives]' [X|XX]
    argv · 2011-03-07 03:40:11 0
  • You can specify various output formats, theme styles, etc. python -m pygments -o source.png source.py python -m pygments -o source.rtf source.py Check available output formats, styles, etc.: python -m pygments -L Find pygments module here: http://pygments.org/


    1
    $ python -m pygments -o source.html source.py
    antrix · 2009-02-06 08:00:02 1
  • Pre-packaged python script that comes with Debian/Ubuntu. Show Sample Output


    1
    colortest-python
    eikenberry · 2012-10-26 06:50:01 0
  • This command builds upon some of the original commands posted here. Additions - The control sequence \x1b(B which selects the default character set ASCII. - Either the \x1B style escape sequence or the \033. - Case insensitivity by using 'I' to include \x1b, \x1B escapes and a-zA-Z in the latter part Tested extensively on makefile unbuffered output where the above additions proved necessary


    0
    sed -r "s/(\x1B|\033)(\(B|\[([0-9]{1,2}(;[0-9]{1,2})?)?[A-Z])//Ig"
    DMaxmatician · 2018-03-08 00:49:39 0

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: