Parameterize formatting string

C

cyril giraudon

Hello,

I 'd like to know if a std::setw() equivalent function exists in
python ?

i thought of something like :

a = 16
"%ai" % 12

But it is not correct.

Any Idea ?

Thanks a lot,

Cyril.
 
D

David

Hello,

I 'd like to know if a std::setw() equivalent function exists in
python ?

i thought of something like :

a = 16
"%ai" % 12

But it is not correct.

Any Idea ?

("%i" % 12).rjust(a)

Or, more ugly:

"%%%di" % a % 12

The first % (after quotes) builds this string: "%16i".
Then the second % operation converts that string to ' 12'

See also: http://docs.python.org/tut/node9.html
 

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,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top