Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8042571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:37:50+00:00 2026-06-05T04:37:50+00:00

I recently (finally?) started to use .format() and have a perhaps a bit obscure

  • 0

I recently (finally?) started to use .format() and
have a perhaps a bit obscure question about it.

Given

res = ['Irene Adler', 35,  24.798]

and

(1) print('{0[0]:10s} {0[1]:5d} {0[2]:.2f}'.format(res))
(2) print('{:{}s} {:{}d} {:{}f}'.format(res[0], 10, res[1], 5, res[2], .2))

work great and both print:

Irene Adler    35 24.80
Irene Adler    35 24.80

I didn’t know that I could deal with lists as in (1) which is neat. I
had seen about field width arguments (2) with the old % formatting before.

My question is about wanting to do something like this which combines (1) and (2):

(3) print('{0[0]:{}s} {0[1]:{}d} {0[2]:{}f}'.format(res, 10, 5, .2))

However, I am unable to do this, and I haven’t been able to figure out
from the documentation if this even possible. It would be nice to just
supply the list to be printed, and the arguments for width.

By the way, I also tried this (w/o luck):

args = (10, 5, .2)
(4) print('{0[0]:{}s} {0[1]:{}d} {0[2]:{}f}'.format(res, args))

In both instances I got:

D:\Users\blabla\Desktop>python tmp.py
Traceback (most recent call last):
  File "tmp.py", line 27, in <module>
    print('{0[0]:{}s} {0[1]:{}d} {0[2]:{}f}'.format(res, 10, 5, .2))
ValueError: cannot switch from manual field specification to automatic field numbering

D:\Users\blabla\Desktop>python tmp.py
Traceback (most recent call last):
  File "tmp.py", line 35, in <module>
    print('{0[0]:{}s} {0[1]:{}d} {0[2]:{}f}'.format(res, args))
ValueError: cannot switch from manual field specification to automatic field numbering

I also tried using zip() to combine the two sequences without luck.

My question is:

Can I specify a list to be printed effectively doing what I was trying
to unsuccessfully do in (3) and (4) (clearly if this is possible, I’m
not using the right syntax) and if so, how?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T04:37:51+00:00Added an answer on June 5, 2026 at 4:37 am

    The error message

    ValueError: cannot switch from manual field specification to automatic field numbering
    

    pretty much says it all: You need to give explicit field indices everwhere, and

    print('{0[0]:{1}s} {0[1]:{2}d} {0[2]:{3}f}'.format(res, 10, 5, .2))
    

    works fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently in our work, I've started getting some experience with SEO (finally). It's something
Recently I have read about hash-tables in a very famous book Introduction to Algorithms
Recently I have got a new 22 monitor. Finally it's possible to keep all
I have recently started creating my own controls and I seem to have a
Having recently introduced an overload of a method the application started to fail. Finally
I have recently stated trying to use the newer style of classes in Python
I've recently decided that I just have to finally learn C/C++, and there is
I recently decided to try jQuery 1.4, excited that I would finally have support
I found out recently that JList (finally!) was generified in JDK7. Why JTree and
Recently I've been thinking about how to transform a complex polygon into a non-complex

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.