程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Not enough values to unpack (expected 2, got 1) solution during Python learning

編輯:Python

This is an article in the process of self-study debug The notes .
May we make progress together .

Problem description

Learn with little turtle Python, In learning to “ file ” When there is a code task , The content is the segmentation and extraction operation based on three dialogues between two characters . Run time error , The main error reported is not enough values to unpack (expected 2, got 1).

(role,line_spoken) = each_line.split(':',1) # Separated by question marks ,1 Stands for split 
ValueError: not enough values to unpack (expected 2, got 1)

Not enough values to decompress , Expected two values , Actually got a value .

Cause of error and solution

  1. Chinese and English symbols are confused and error is reported . This error command appears , Probably because of split The colon in the command is wrong , The colon in Chinese is shaped like :, And in English :, There is still a big difference .
    》》 Check out your TXT Is the document Chinese or English colon , The two correspond
  2. There is extra space . This error reporting reason is still relatively difficult to be found , I made this mistake from the beginning , because TXT The default when the document is copied , There are a few blank lines at the end of the document .
    》》 Look at the cursor position , Delete the blank line

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved