selfteaching / selfteaching/selfteaching-python-camp
Day09 作业中读取tang300.json文件出错的解决方法
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 151
- Forks
- 875
- PR merge metrics
- No merged PRs in 30d
Description
错误代码如下:
UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 73: illegal multibyte sequence
出现这个问题可能是因为文件不是UTF8编码的,所以改为对应的编码方式即可。
#原语句
with open('tang300.json') as f:
text = f.read()
f.closed
#修改后
with open('tang300.json','r',encoding='UTF-8') as f:
text = f.read()
f.closed
(网上有说修改读取方式也行:with open('tang300.json','rd') as f: ,但是我试了不行,大家好奇可以试试。)
这样就好了,如果词频结果出现了英文,可以把英文限制为输出0个解决。也可以更改词频代码。
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Day09 exercise and the referenced tang300.json file, then reproduce the UnicodeDecodeError from the original open call. Check how the exercise currently explains file encoding and update the relevant guidance so the documented fix and expected word-frequency result are clear.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- documentation
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100