Traceback (most recent call last): File "C:/Users/Sure/PyProject/day08/作业/05 文件转列表字典.py", line 16, in <module> k, v = i.split() ValueError: not enough values to unpack (expected 2, got 1)
错误代码:
1 2 3 4 5 6 7 8 9 10 11 12 13
l = [] withopen('a2.txt', 'r', encoding='utf-8') as f: for line in f: lst = line.split() kv = [] for i in lst: k, v = i.split() # 这里错了 if v.isdecimal(): v = int(v) kv.append((k, v)) dic = dict(kv) l.append(dic) print(l)
l = [] withopen('a2.txt', 'r', encoding='utf-8') as f: for line in f: lst = line.split() kv = [] for i in lst: k, v = i.split(':') if v.isdecimal(): v = int(v) kv.append((k, v)) dic = dict(kv) l.append(dic) print(l)
I/O operation on closed file.
错误2.1
报错信息:
1 2 3 4 5 6
Traceback (most recent call last): File 第二周大作业-博客园.py, line 91, in <module> dic[choose]() File 第二周大作业-博客园.py, line 23, in register f.write(f"{j['name']}{j['pwd']}{j['count']}\n") ValueError: I/O operation on closed file.
错误代码:
1 2 3 4
withopen('temp', 'w', encoding='utf-8') as f1: for j in user_info: f.write(f"{j['name']}{j['pwd']}{j['count']}\n") f.flush()
withopen('temp', 'w', encoding='utf-8') as f1: for j in user_info: f1.write(f"{j['name']}{j['pwd']}{j['count']}\n") f1.flush()
substring not found
错误3.1
报错信息:
1 2 3 4
Traceback (most recent call last): File "C:/Users/Sure/PyProject/week05-国庆假期/test.py", line 6, in <module> print(s.index('ll')) ValueError: substring not found
错误代码:
1 2 3
s = 'alex' print(s.index('le')) print(s.index('ll'))
s = 'alex' print(s.index('le')) print(s.find('ll'))
too many values to unpack
错误4.1
报错信息:
1 2 3 4 5 6 7 8 9 10 11 12
Traceback (most recent call last): File "C:/Users/Sure/PyProject/神器/hexo-migration/bin/run.py", line 3, in <module> src.run() File "C:\Users\Sure\PyProject\神器\hexo-migration\core\src.py", line 16, in run migration_handler.migrate() File "C:\Users\Sure\PyProject\神器\hexo-migration\utils\MigrationHandler.py", line 152, in migrate self.file_write() File "C:\Users\Sure\PyProject\神器\hexo-migration\utils\MigrationHandler.py", line 54, in file_write self.yaml_front_matter_generator() File "C:\Users\Sure\PyProject\神器\hexo-migration\utils\MigrationHandler.py", line 23, in yaml_front_matter_generator for k, v in self.title_dict: ValueError: too many values to unpack (expected 2)
错误代码:
1 2
for k, v in self.title_dict: yaml_str = yaml_str + k + ': ' + v + '\n'