Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I use this code to align the output

template = "{0:20}{1:5}"
print template.format("1","bread")

1      bread
2      cheese

but what if I want the output to be like this

1 .... bread
2 .... cheese

can any one help me ?

share|improve this question
3  
Have you considered adding dots to the template string? –  inspectorG4dget 35 mins ago

2 Answers 2

According to the format mini-language specification, you need to add .< before 20. This would basically say format() to use . as a "fill" character.

Before:

>>> template = "{0:20}{1:5}"
>>> print template.format("1","bread")
1                   bread

After:

>>> template = "{0:.<20}{1:5}"
>>> print template.format("1","bread")
1...................bread
share|improve this answer

Perhaps you should try

template = "{0:2}.... {1:5}"
print template.format("1", "bread")

1 .... bread

If you want a variable number of dots, you might try

template = "{0:.<20}{1:5}"
print template.format("1", "bread")

1....................bread
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.