“ValueError:格式中的零长度字段名称"Python 3.0,3.1,3.2 中的错误 [英] "ValueError: zero length field name in format" error in Python 3.0,3.1,3.2

查看:26
本文介绍了“ValueError:格式中的零长度字段名称"Python 3.0,3.1,3.2 中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试学习 Python(更具体地说是 3),但出现此错误:

I'm trying learn Python (3 to be more specific) and I'm getting this error:

ValueError: zero length field name in format

我用谷歌搜索了一下,发现你需要指定数字:

I googled it and I found out you need to specify the numbers:

a, b = 0, 1
if a < b:
     print('a ({0}) is less than b ({1})'.format(a, b))
else:
     print('a ({0}) is not less than b ({1})'.format(a, b))

而不是像教程(来自 lynda.com)实际上所说的那样:

And not like the tutorial (from lynda.com) actually says to do:

a, b = 0, 1
if a < b:
     print('a ({}) is less than b ({})'.format(a, b))
else:
     print('a ({}) is not less than b ({})'.format(a, b))

我接下来的教程有 Python 3.1,我使用的是 3.2,我读到的关于这个错误的信息是这只会发生在 <3.1 (3.0) 中.他们是在 3.2 中撤消了这一点,还是我做错了什么?

The tutorial im following has Python 3.1, and im using 3.2 and what i read about this error is that this only happens in <3.1 (3.0). Did they undo this in 3.2, or am i doing something wrong?

另外,慢慢说;) 这确实是我学习 Python 的第一个晚上,也是我用 Python 编写的第二个脚本".

Also, speak slowly ;) this is literally my first night learning Python and only the 2nd "script" i've written in Python.

推荐答案

我猜你会以某种方式意外运行 python 2.6.

I'm gonna guess that you are running python 2.6 by accident somehow.

如果您使用的是 python 3,则此功能仅适用于至少 3.1,如果您使用的是 python 2,则此功能至少适用于 2.7.

This feature is only available for at least 3.1 if you are using python 3, or 2.7 if you are using python 2.

这篇关于“ValueError:格式中的零长度字段名称"Python 3.0,3.1,3.2 中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆