[Python-ideas] input function: built-in space between string and user-input

Terry Reedy tjreedy at udel.edu
Tue May 15 23:19:49 CEST 2012


On 5/15/2012 6:46 AM, 
Suriaprakash.Mariappan at smsc.com wrote:
> *_print function: built-in space between string and variable:_*
>
> The below python code,
>
> */length = 5/*
> */print('Length is', length)/*
>
> gives an output of
>
> */Length is 5/*

The */.../* and *_..._* bracketing makes you post harder to read. 
Perhaps this is used in India, but not elsewhere. Omit next time.

> Even though we have not specified a space between 'Length is' and the
> variable length, Python puts it for us so that we get a clean nice
> output and the program is much more readable this way (since we don't
> need to worry about spacing in the strings we use for output). This is
> surely an example of how Python makes life easy for the programmer.
>
> *_input function: built-in space between string and user-input:_*
>
> However, the below python code,
>
> */guess = int(input('Enter an integer'))/*
>
> gives an output of
>
> */Enter an integer7/*
>
> [Note: Assume 7 is entered by the user.]
>
> *Suggestion: *Similar to the printf function, for the input function
> also, it will be nice to have the Python put a space between string and
> user-input, so that the output in the above case will be more readable
> as below.
>
> */Enter an integer 7/*

print() converts objects to strings and adds separators and a terminator 
before writing to outfile.write(). In 3.x, the separator, terminator, 
and outfile can all be changed from the default. The user is stuck with 
the fact that str(obj) is what it is, so it is handy to automatically 
tack something on.

input() directly writes a prompt string with sys.stdout.write.
There is no need to to augment that as the user can make the prompt 
string be whatever they want. In any case, a change would break 
back-compatibility.

-- 
Terry Jan Reedy




More information about the Python-ideas mailing list