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

前端 未结 3 2007
盖世英雄少女心
盖世英雄少女心 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:05

    Well if can give a proper output in a table format if instead of using format go for f"" ;

    for e.g

    <!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>

    0 讨论(0)
  • 2020-12-14 15:19
    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.

    0 讨论(0)
  • 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)
    
    0 讨论(0)
提交回复
热议问题