1

Using the code print('{0} is not'.format('That that is not')) in Python 3.1.1, I get the following error:

AttributeError: 'str' object has no attribute 'format'

when I delete the line Netbeans automatically inserted at the beginning:

from distutils.command.bdist_dumb import format

which itself causes an error of

ImportError: cannot import name format

What am I doing wrong here?

1 Answer 1

6

You must be running an older version of Python. This does work in Python 3.1.1+:

$ python3
Python 3.1.1+ (r311:74480, Nov  2 2009, 14:49:22) 
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> '{0} is not'.format('That that is not')
'That that is not is not'

You will, however, get this error in Python 2.5.4:

$ python2.5
Python 2.5.4 (r254:67916, Jan 20 2010, 21:44:03) 
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> '{0} is not'.format('That that is not')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'str' object has no attribute 'format'

This feature seems to have been backported to Python 2.6, so you won't get this error there. You must be running Python < 2.6.

Sign up to request clarification or add additional context in comments.

4 Comments

Weird... I am running < 2.6 in Netbeans but installed Python 3 on my machine. Netbeans must've installed Python itself? EDIT: OH, I get it now! Netbeans installed Jython by itself, which is only at 2.5 :(
You should be able to configure which version of Python your Netbeans project uses: wiki.netbeans.org/…
re voting: Thanks. It might work if you try again tomorrow. I believe SO has a daily limit, not a life-time limit.
Thanks! I finally got Netbeans wokring the way I want :)

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.