[Python-ideas] input function: built-in space between string and user-input
Michael Foord
fuzzyman at gmail.com
Wed May 16 11:28:54 CEST 2012
On 15 May 2012 22:19, Terry Reedy <tjreedy at udel.edu> wrote:
> On 5/15/2012 6:46 AM, Suriaprakash.Mariappan at smsc.**com<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.
>
They weren't present in the version I read. Probably a consequence of your
mail client not being able to display formatted emails.
Michael
>
> 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
>
> ______________________________**_________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/**mailman/listinfo/python-ideas<http://mail.python.org/mailman/listinfo/python-ideas>
>
--
http://www.voidspace.org.uk/
May you do good and not evil
May you find forgiveness for yourself and forgive others
May you share freely, never taking more than you give.
-- the sqlite blessing http://www.sqlite.org/different.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20120516/4f84da1a/attachment.html>
More information about the Python-ideas
mailing list