ValueError: cannot switch from manual field specification to automatic field numbering

前端 未结 3 2024
盖世英雄少女心
盖世英雄少女心 2020-12-14 14:54

The class:

class Book(object):
    def __init__(self, title, author):
        self.title = title
        self.author = author

    def get_entry(self):
              


        
3条回答
  •  醉话见心
    2020-12-14 15:27

    return "{0} by {1} on {}".format(self.title, self.author, self.press)
    

    that doesn't work. If you specify positions, you have to do it through the end:

    return "{0} by {1} on {2}".format(self.title, self.author, self.press)
    

    In your case, best is to leave python treat that automatically:

    return "{} by {} on {}".format(self.title, self.author, self.press)
    

提交回复
热议问题