Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 字符串格式错误_Python_String_Format - Fatal编程技术网

Python 字符串格式错误

Python 字符串格式错误,python,string,format,Python,String,Format,在Python 3.1.1中使用代码打印“{0}不是”。格式化“那不是”,我得到以下错误: AttributeError: 'str' object has no attribute 'format' 删除开头自动插入的行Netbeans时: from distutils.command.bdist_dumb import format 这本身会导致错误的 ImportError: cannot import name format 我做错了什么?您一定在运行较旧版本的Python。这在P

在Python 3.1.1中使用代码打印“{0}不是”。格式化“那不是”,我得到以下错误:

AttributeError: 'str' object has no attribute 'format'
删除开头自动插入的行Netbeans时:

from distutils.command.bdist_dumb import format
这本身会导致错误的

ImportError: cannot import name format

我做错了什么?

您一定在运行较旧版本的Python。这在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'
但是,在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'

这个特性似乎已经被后移植到了Python2.6中,所以您不会在那里看到这个错误。必须运行Python<2.6。

必须运行较旧版本的Python。这在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'
但是,在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'

这个特性似乎已经被后移植到了Python2.6中,所以您不会在那里看到这个错误。您必须运行Python<2.6。

奇怪。。。我在Netbeans中运行<2.6,但在我的机器上安装了Python 3。Netbeans一定是自己安装了Python?编辑:哦,我现在明白了!Netbeans是自己安装Jython的,只有2.5版本:您应该能够配置Netbeans项目使用的Python版本:重新投票:谢谢。如果你明天再试一次,它可能会起作用。我相信这是一个每日限制,而不是终身限制。谢谢!我终于找到了我想要的方式:怪异。。。我在Netbeans中运行<2.6,但在我的机器上安装了Python 3。Netbeans一定是自己安装了Python?编辑:哦,我现在明白了!Netbeans是自己安装Jython的,只有2.5版本:您应该能够配置Netbeans项目使用的Python版本:重新投票:谢谢。如果你明天再试一次,它可能会起作用。我相信这是一个每日限制,而不是终身限制。谢谢!我终于得到了我想要的Netbeans wokring: