views:

84

answers:

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?

+5  A: 

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.

allyourcode
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 :(
wrongusername
btw, I'd like to upvote you, but reach my vote limit :(
wrongusername
You should be able to configure which version of Python your Netbeans project uses: http://wiki.netbeans.org/NetBeansPythonTutorial#Setting_Your_Platform_Runtime
allyourcode
re voting: Thanks. It might work if you try again tomorrow. I believe SO has a daily limit, not a life-time limit.
allyourcode
Thanks! I finally got Netbeans wokring the way I want :)
wrongusername