0

In python I wrote:

list_of_assets = []
list_of_assets.append(('A', 'B', 'C'))
for asset in list_of_assets:
    print('{:15}   {:30}   {:30}'.format([asset[0], asset[1], asset[2]]))

But I get:

print('{:15}   {:30}   {:30}'.format([asset[0], asset[1], asset[2]]))
TypeError: non-empty format string passed to object.__format__

why is that?

3 Answers 3

2

Don't wrap the format parameters in a list:

list_of_assets = []
list_of_assets.append(('A', 'B', 'C'))
for asset in list_of_assets:
    #                              here  ↓                  and here ↓
    print('{:15}   {:30}   {:30}'.format(asset[0], asset[1], asset[2]))

output:

A                 B                                C                             

Even better, you could use parameter expansion:

for asset in list_of_assets:
    print('{:15}   {:30}   {:30}'.format(*asset))
Sign up to request clarification or add additional context in comments.

Comments

0

The error came because you passed a list argument to the format function. Pass individual elements of the list instead.

Your code should be like this:

list_of_assets = []
list_of_assets.append(('A', 'B', 'C'))
for asset in list_of_assets:
    print('{:15}   {:30}   {:30}'.format(asset[0], asset[1], asset[2]))

Comments

0

Use this code

list_of_assets = []
list_of_assets.append(('A', 'B', 'C'))
for asset in list_of_assets:
    print('{:15}   {:30}   {:30}'.format(asset[0],asset[1],asset[2]))

1 Comment

Please don't post only code as answer, but also provide an explanation what your code does and how it solves the problem of the question. Answers with an explanation are usually more helpful and of better quality, and are more likely to attract upvotes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.