ValueError: cannot switch from manual field specification to automatic field numbering
ValueError: cannot switch from manual field specification to automatic field numbering
class:
class Book(object):
def __init__(self, title, author):
self.title = title
self.author = author
def get_entry(self):
return "{0} by {1} on {}".format(self.title, self.author, self.press)
从中创建我的书的实例:
In [72]: mybook = Book('HTML','Lee')
In [75]: mybook.title
Out[75]: 'HTML'
In [76]: mybook.author
Out[76]: 'Lee'
请注意,我没有初始化属性 'self.press',而是在 get_entry method.Go 之前使用它来输入数据。
mybook.press = 'Murach'
mybook.price = 'download'
到目前为止,我可以用vars
指定所有数据输入
In [77]: vars(mybook)
Out[77]: {'author': 'Lee', 'title': 'HTML',...}
我在 console.When 尝试调用 get_entry 方法时硬输入了很多关于 mybook 的数据,错误报告。
mybook.get_entry()
ValueError: cannot switch from manual field specification to automatic field numbering.
所有这一切都在 console.I 的交互模式下进行,珍惜输入的数据,进一步 pickle mybook
文件中的对象。然而,它是有缺陷的。如何在交互模式下拯救它。
或者我必须重新开始。
return "{0} by {1} on {}".format(self.title, self.author, self.press)
那是行不通的。如果指定位置,则必须执行到最后:
return "{0} by {1} on {2}".format(self.title, self.author, self.press)
对于您的情况,最好让 python 自动处理:
return "{} by {} on {}".format(self.title, self.author, self.press)
print ("{0:.1f} and the other no {0:.2f}".format(a,b))
python cannot do both manual and automatic precision handling (field numbering) in a single execution of code. You can either go for specifying the field numbering for each variable or let python do it automatically for all.
好吧,如果可以 table 格式给出正确的输出,如果
而不是使用 format go for f"" ;
例如
<!DOCTYPE html>
<html>
<head>
<title><strong>Unable to handle Value Error</strong></title>
</head>
<body>
<p><ol>for name, branch,year in college:</ol>
<ol> print(f"{name:{10}} {branch:{20}} {year:{12}} )</ol>
<ol>name branch year </ol>
<ol>ankit cse 2</ol>
<ol>vijay ece 4</ol>
<ol> raj IT 1</ol>
</body>
</html>
class:
class Book(object):
def __init__(self, title, author):
self.title = title
self.author = author
def get_entry(self):
return "{0} by {1} on {}".format(self.title, self.author, self.press)
从中创建我的书的实例:
In [72]: mybook = Book('HTML','Lee')
In [75]: mybook.title
Out[75]: 'HTML'
In [76]: mybook.author
Out[76]: 'Lee'
请注意,我没有初始化属性 'self.press',而是在 get_entry method.Go 之前使用它来输入数据。
mybook.press = 'Murach'
mybook.price = 'download'
到目前为止,我可以用vars
In [77]: vars(mybook)
Out[77]: {'author': 'Lee', 'title': 'HTML',...}
我在 console.When 尝试调用 get_entry 方法时硬输入了很多关于 mybook 的数据,错误报告。
mybook.get_entry()
ValueError: cannot switch from manual field specification to automatic field numbering.
所有这一切都在 console.I 的交互模式下进行,珍惜输入的数据,进一步 pickle mybook
文件中的对象。然而,它是有缺陷的。如何在交互模式下拯救它。
或者我必须重新开始。
return "{0} by {1} on {}".format(self.title, self.author, self.press)
那是行不通的。如果指定位置,则必须执行到最后:
return "{0} by {1} on {2}".format(self.title, self.author, self.press)
对于您的情况,最好让 python 自动处理:
return "{} by {} on {}".format(self.title, self.author, self.press)
print ("{0:.1f} and the other no {0:.2f}".format(a,b))
python cannot do both manual and automatic precision handling (field numbering) in a single execution of code. You can either go for specifying the field numbering for each variable or let python do it automatically for all.
好吧,如果可以 table 格式给出正确的输出,如果 而不是使用 format go for f"" ;
例如
<!DOCTYPE html>
<html>
<head>
<title><strong>Unable to handle Value Error</strong></title>
</head>
<body>
<p><ol>for name, branch,year in college:</ol>
<ol> print(f"{name:{10}} {branch:{20}} {year:{12}} )</ol>
<ol>name branch year </ol>
<ol>ankit cse 2</ol>
<ol>vijay ece 4</ol>
<ol> raj IT 1</ol>
</body>
</html>