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

  • Home
  • SEARCH
  • 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 8995405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:36:57+00:00 2026-06-15T23:36:57+00:00

>>> ‘string with no string formatting markers’ % [‘string’] ‘string with no string formatting

  • 0
>>> 'string with no string formatting markers' % ['string']
'string with no string formatting markers'
>>> 'string with no string formatting markers' % ('string',)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: not all arguments converted during string formatting

I would expect both cases to raise a TypeError, but this is not the case. Why not?

The Python documentation on this subject talks about strings, tuples and dictionaries, but says nothing about lists. I’m a bit confused about this behavior. I’ve been able to duplicate it in Python 2.7 and 3.2.

  • 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-15T23:36:57+00:00Added an answer on June 15, 2026 at 11:36 pm

    Reading carefully, the documentation states that:

    If format requires a single argument, values may be a single non-tuple
    object. Otherwise, values must be a tuple with exactly the number
    of items specified by the format string, or a single mapping object
    (for example, a dictionary).

    Now, in this case the format does not require a single argument and thus the documentation tells us that you should use a tuple or a mapping as argument; other cases fall in “undefined behaviour”(which is what is happening: the behaviour is not consistent in all cases).

    This should probably be considered the final answer to the question: if the string does not have any format specifier, using a list(or any kind different from tuple or a mapping) should simply be considered a bug by itself leading to undefined behaviour.

    From this follows that you ought to always use a tuple or dict as argument, otherwise you have to check for format specifiers by hand or handle odd behaviours.

    In your case you can probably fix the problem using (['string'], ) instead of ['string'].


    Possible “explanation” of why the resultant behaviour seems to be so random:

    It seems like there was a buggy check in the original implementation of PyString_Format/PyUnicode_Format, instead of using PyMappingCheck on this line:

    if (PyMapping_Check(args) && !PyTuple_Check(args) &&
         !PyObject_TypeCheck(args, &PyBaseString_Type))
        dict = args;
    

    It was used this code:

    if (Py_TYPE(args)->tp_as_mapping && !PyTuple_Check(args) &&
        !PyObject_TypeCheck(args, &PyBaseString_Type))
        dict = args;
    

    which is not equivalent. For example set does not have tp_as_mapping set(at least in the Python2.7.3 source code that I have downloaded some weeks ago), while list does set it.

    This might be the reason why list(and possibly other objects) do not raise the TypeError while, set, int and many others do.

    As I stated before in this same answer I do get TypeError even with lists:

    $ python2
    Python 2.7.3 (default, Sep 26 2012, 21:53:58) 
    [GCC 4.7.2] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 'some string' % []
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: not all arguments converted during string formatting
    

    This probably shows that the above issue is not the only one here.

    Looking at the source code I agree that, in theory, the number of arguments is not checked if the argument is not a tuple, but this would imply 'some string' % 5 -> 'some string' and not a TypeError, so there must be something fishy in that code.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I've got a string that has curly quotes in it. I'd like to replace
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
i got an object with contents of html markup in it, for example: string
Does anyone know how can I replace this 2 symbol below from the string
I have a reasonable size flat file database of text documents mostly saved in
string formIdList = 8256, 8258, 8362, 8120, 8270, 8271, 8272, 8273, 8257, 8279, 8212,
The problem with unsigned char. I am reading a PPM image file which has
I would like to count the length of a string with PHP. The string

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.