py3k - format specifier for strings

C

Carl Trachte

Hello.
Python 3.0.a1 has been released. I'm trying to get the hang of the new
string formatting in the form:
'5.66'

There are more options in PEP 3101 (fill, alignment, etc.), but I'm having
trouble implementing them. The doc has not yet been written. I haven't
consulted the source code yet.

Any help in the way of examples would be appreciated.

Carl T.
 
?

=?ISO-8859-15?Q?=22Martin_v=2E_L=F6wis=22?=

a = "{0}".format(5.66)
'5.66'

There are more options in PEP 3101 (fill, alignment, etc.), but I'm having
trouble implementing them.

It would be good if you could describe these troubles in more detail.
What have you been trying, what happened, and what did you expect to
happen instead?
Any help in the way of examples would be appreciated.

From test_unicode.py:

"My name is {0}".format('Fred')
"My name is {0[name]}".format(dict(name='Fred')
"My name is {0} :-{{}}".format('Fred')

d = datetime.date(2007, 8, 18)
"The year is {0.year}".format(d)

'{0:.3s}'.format('abc')
'{0:.0s}'.format('abcdef')
'{0:3.3s}'.format('abc')
'{0:3.2s}'.format('abc')
'{0:x<0s}'.format('result')
'{0:x<7s}'.format('result')
'{0:^10s}'.format('result')
'{0!s}'.format('Hello')
'{0!s:15s}'.format('Hello')
'{0!r:}'.format('Hello')

Regards,
Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top