Dear python developpers,
First I'd like to thank you for your work, you're making the world simple !
Then I would like to share a very light suggestion for the improvement of python, I hope I am using the right way for this.
(I am using python 3.4.3)
I am from the science side, more precisely physics, and I often have to display or log formatted numbers during computations.
Usually I have numbers with many digits and it is necessary for me to use the right format for display (for setting the number of digits after coma, for using exponent notation, etc...) I was using the way of the "%" until I found the __builtins__.format function.
But I still cannot remember all the letters for the possible options, such as presented in the part named "7.1.3.1. Format Specification Mini-Language" of this page :
And each time I need to remind of the mini-language, I need to open a web-page or a file and it is breaking my workflow.
So I think it would be helpful that the "format.__doc__" string would contains a quick example showing the way to set the number of digits, the appearance conditions of the signs as well as a quick reminder of the "Mini-language" types.
I have made a template of the docstring to begin with, that I send as an attached file, but I am not familiar with docstring format.
Also, there is maybe more material to add to the docstring that will be likely to help other people the same way.
I hope you like the idea,
Yours sincerely,
Hugo Prod'homme.
>>> 'number is : {:03.2f}'.format(2) 'number is : 2.00' >>> 'number is : {:03.2f}'.format(2.3555) 'number is : 2.36'
>>> '{:+f}; {:+f}'.format(3.14, -3.14) # show it always '+3.140000; -3.140000' >>> '{: f}; {: f}'.format(3.14, -3.14) # show a space for positive numbers ' 3.140000; -3.140000' >>> '{:-f}; {:-f}'.format(3.14, -3.14) # show only the minus -- same as '{:f}; >>> {:f}' '3.140000; -3.140000' "b" : Binary format. "c" : Character. "d" : Decimal Integer. "e" : Exponent notation. "E" : Exponent notation, upper case 'E'. "f" : Fixed point "F" : Fixed point. Same as 'f'. "g" : General format. "G" : General format, switches to 'E' if the number gets too large. The representations of infinity and NaN are uppercased, too. "n" : Number. This is the same as 'g', except that it uses the current locale setting to insert the appropriate number separator characters. "o" : Octal format. "s" : String format. "x" : Hex format, using lower- case letters for the digits above 9. "X" : Hex format, using upper- case letters for the digits above 9. "%" : Percentage. None : Thesame as 'g'.
_______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com