Python将两个字典合并的方法为:
>>> dic2={"2":"world"}
>>> dic1.update(dic2)
>>> print(dic1)
{'1': 'hello', '2': 'world'}
>>> print(dic2)
{'2': 'world'}
可以看到dict1.update(dict2)即可将字典2合并进入dict1中。
Python写文件时,出现
UnicodeEncodeError: 'gbk' codec can't encode character '\u05b2' in position 64: illegal multibyte sequence
的错误,原因是编码的问题
之前的代码为
with open("..\m.html",'w') as f:
f.write(html)
只需要改成
with open("..\m.html",'w',encoding='utf-8') as f:
f.write(html)
即可。