ValueError: need more than 1 value to unpack python

后端 未结 4 1345
抹茶落季
抹茶落季 2020-12-06 18:01

I have got an existing menu that gives you options L or D. L should load the contents of a file and D should display it.<

4条回答
  •  天命终不由人
    2020-12-06 18:24

    If you want to work around that without adding extra lines and checks, one solution is to change your split to the following:

    name, adult, child, garbage = (line+',,,').split(',', maxsplit=3)
    

    This will silently ignore the missing values, and the variables will be empty. Meaning, the values for name, adult and child will be filled if they are there, and will be empty it the original file doesn't have them. For all intents and purposes, ignore the variable garbage.

提交回复
热议问题