Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: significance of -u option?

Tags:

python

I am noticed in some python code that -u is used to start the python interpreter. I looked at the man page for python but I could not get much out of it. Please give me some examples.

like image 786
Shraddha Avatar asked Jan 10 '13 12:01

Shraddha


People also ask

What is the purpose of an option?

An option gives you the right, but not the obligation, to buy or sell an underlying asset at a specific price on or before a certain date.

How do you benefit from options?

A put option buyer makes a profit if the price falls below the strike price before the expiration. The exact amount of profit depends on the difference between the stock price and the option strike price at expiration or when the option position is closed.

Why is option strategy important?

For speculators, options can offer lower-cost ways to go long or short the market with limited downside risk. Options also give traders and investors more flexible and complex strategies such as spread and combinations that can be potentially profitable under any market scenario.

What is the effect of an option?

Option Effect means any change, event, modification, restatement, revision, update, development, result or effect that directly or indirectly arises or results from or relates to Parent's historical stock option granting practices and related accounting, tax treatment, reporting, disclosure and investigation thereof ...


2 Answers

From python --help:

-u     : unbuffered binary stdout and stderr; also PYTHONUNBUFFERED=x          see man page for details on internal buffering relating to '-u' 

The manpage states:

-u     Force  stdin,  stdout and stderr to be totally unbuffered.  On systems where it matters, also put stdin,        stdout and stderr in binary mode.  Note that there is internal buffering  in  xreadlines(),  readlines()        and  file-object  iterators  ("for  line in sys.stdin") which is not influenced by this option.  To work        around this, you will want to use "sys.stdin.readline()" inside a "while 1:" loop. 

Python opens the stdin, -out and -error streams in a buffered mode; it'll read or write in larger chunks, keeping data in memory until a threshold is reached. -u disables those buffers.

Also, python can interpret newlines on open files and translate them from and to the native platform newlines (text mode). The -u option disables this translation, allowing you to process binary data without having to worry about what might happen to \r\n combinations. It is the equivalent of using rb or wb modes when opening files with the open() function.

like image 93
Martijn Pieters Avatar answered Sep 28 '22 16:09

Martijn Pieters


Python is optimised for reading in and printing out lots of data. One of these optimisation is that the standard input and output of the Python interpreter are buffered. That means that whenever a program tries to use one of those streams, the interpreted will block up the usage into large chunks and then send the chunks all in one go. This is faster than sending each individual read/write through separately, but obviously has the disadvantage that data can get 'stopped up' in the middle.

The -u flag turns off this behaviour.

like image 43
Katriel Avatar answered Sep 28 '22 16:09

Katriel