Thursday, January 7, 2010

Fun With Python 3.1's New String Formatting . . .

Or a totally unoriginal poor ASCII art rendition of the Transamerica building at night . . .

carl@L733rLinux:~$ python
Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from __future__ import print_function

>>> # saw this on Python-Dev (Stephen Bethard?)
>>> format('HEADER', '*^50')
'**********************HEADER**********************'
# just for fun . . .
>>> for x in range(30):
...     print('{0:*^50}'.format(x * ' '))
...
**************************************************
************************ *************************
************************  ************************
***********************   ************************
***********************    ***********************
**********************     ***********************
**********************      **********************
*********************       **********************
*********************        *********************
********************         *********************
********************          ********************
*******************           ********************
*******************            *******************
******************             *******************
******************              ******************
*****************               ******************
*****************                *****************
****************                 *****************
****************                  ****************
***************                   ****************
***************                    ***************
**************                     ***************
**************                      **************
*************                       **************
*************                        *************
************                         *************
************                          ************
***********                           ************
***********                            ***********
**********                             ***********
>>>


If that isn't beautiful, I don't know what is . . .


1 comment:

  1. Nice comments from your site.Thank u your nice post.I really love your post Thank ...

    network

    ReplyDelete