The first Issue... closed :)

Thanks all

  • 加上 encoding = 'utf-8' 后,的确中文版的weather_info读取ok了(包括第一行),程序也运转正常。
  • 但是英文版的weather_info2读取时第一行还是有问题,始终会有一个"\ufeff"出现在第一字符串Hangzhou之前。查询后得知原来问题如下: Python会自动加一些特殊字符串在代码的头部,但这些不会显示在你的文档中,等你执行代码时它就会报错,错误显示在第一行,如果用read()去看,就会在第一行看到"u\feff"
  • 解决方案,按照如下介绍,我将英文版的文档内容拷贝到我的notepad++, 然后在保存时选择Encoding 下拉菜单中的"Encoding in ANSI", 保存为新的weather.txt文件,然后再跑程序,一切终于都正常了.....

"\ufeff" 报错问题查询链接与解决方案

"This problem arise basically when you save your python code in a UTF-8 or UTF-16 encoding because python add some special character at the beginning of the code automatically (which is not shown by the text editors) to identify the encoding format. But, when you try to execute the code it gives you the syntax error in line 1 i.e, start of code because python compiler understands ASCII encoding. when you view the code of file using read() function you can see at the begin of the returned code '\ufeff' is shown. *** The one simplest solution to this problem is just by changing the encoding back to ASCII encoding(for this you can copy your code to a notepad and save it Remember! choose the ASCII encoding...*** Hope this will help."


图片发自简书App
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 雨下了一天,却说不上大,就像撒娇的小孩子,想起来了就抽抽噎噎地哭上一阵儿。但温度的确是降下来了,傍晚走在外面时,挺...
    暮暮蜜阅读 223评论 0 0
  • 每个人都有每个人的状态,每个人都有每个人的生活状态。今天回到家看到爸妈都在床上躺着,平时这个时候家里是没人的,不过...
    果然太弱阅读 185评论 0 1
  • 《我没有哭》 我没有哭,只是当下的表情有些无语。 《小学生》 总有人在感叹大学生不如农民工,说得好像小学生就能超神...
    何鲸洛阅读 288评论 0 0
  • 近段时间,忙着学演讲,忙着学写作,忙着看书,忙着练字,可忙着忙着却把自己的本职工作忙忘了。 现在这份工作,我已经做...
    小馒头0601阅读 191评论 2 3
  • 还有十分钟 我不敢 奢求什么 只祈祷那甘甜的风 九块九包邮的蜂蜜 勾了糖精 四毛五的小笼包 纸壳加葱 没有嚼过草根...
    俗人杂文阅读 256评论 0 3