【问题记录】Python出现NoneType.

编程入门 行业动态 更新时间:2024-10-08 02:21:52

【问题记录】<a href=https://www.elefans.com/category/jswz/34/1770869.html style=Python出现NoneType."/>

【问题记录】Python出现NoneType.

问题记录:

调试程序时,发现报错:

 File "C:\Users\HP\PycharmProjects\pythonProject\StudentScoreManagerSystem\stusystem.py", line 297, in <module>main()File "C:\Users\HP\PycharmProjects\pythonProject\StudentScoreManagerSystem\stusystem.py", line 32, in mainshow()File "C:\Users\HP\PycharmProjects\pythonProject\StudentScoreManagerSystem\stusystem.py", line 291, in showshow_student(student_list)File "C:\Users\HP\PycharmProjects\pythonProject\StudentScoreManagerSystem\stusystem.py", line 146, in show_studentprint(format_data.format(item.get('id'),
TypeError: unsupported format string passed to NoneType.__format__

问题描述:

TypeError: unsupported format string passed to NoneType.__format__, 翻译过来是,format格式化输出不支持NoneType类型。

原因分析:

读取文件中学生信息时,对应位置没有内容(获取到的值为 NoneType为空,或者读的值不对应),导致出错。


解决方案:

经过排查发现,是由于自己的粗心大意,在写入文件时为:

student = {'id': id, 'name': name, 'english': english, 'python': python, 'shuxue': shuxue, 'avg': int(avg),'sthhu': stuhu, 'teach': teach, 'zonghe': int(zonghe)}

再看下面的读取文件:

    for item in lst:print(format_data.format(item.get('id'),item.get('name'),item.get('english'),item.get('python'),item.get('shuxue'),item.get('avg'),item.get('stuhu'),item.get('teach'),item.get('zonghe')))

发现问题所在了,读取的是’stuhu’,存入文件的是’sthhu’,赶紧修改,问题解决了。

更多推荐

【问题记录】Python出现NoneType.

本文发布于:2024-02-13 16:04:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1759284.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Python   NoneType

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!