打开city.py文件时报错

问题原因:

程序中的编码错误,python默认是acii模式,没有支持utf8。如果代码中有汉字 ,就会报错

解决方案:

源代码文件(city.py)第一行添加:#coding:utf-8

特别提示:windows 如果查询无结果,请用 #coding: gbk,并且保证 city.py 开头也有这一行声明。

Python读文件报错:SyntaxError: Non-ASCII character in file的更多相关文章

  1. 【python】python读取文件报错UnicodeDecodeError: 'gbk' codec can't decode byte 0xac in position 2: illegal multibyte sequence

    python读取文件报错UnicodeDecodeError: 'gbk' codec can't decode byte 0xac in position 2: illegal multibyte ...

  2. Python创建文件报错OSError:[Errno 22] Invalid argument处理

    问题: windows平台下使用python open函数w模式打开文件报错“OSError: [Errno 22] Invalid argument: '../news/“消费升维”成零售业新风口? ...

  3. python读取文件报错:pandas.errors.ParserError: iterator should return strings, not bytes (did you open the file in text mode?)

    python 读取csv文件报错问题 import csv with open('E:/Selenium2script/DDT模块/test.csv','rb') as f: readers = cs ...

  4. ar 解压一个.a文件报错: xxx.a is a fat file (use libtool(1) or lipo(1) and ar(1) on it)

    Linux  使用终端指令 ar x /Users/apple/Desktop/libWC_LIB_SDKT.a解压一个文件 报错如图所示: 是因为该.a文件包含了多个cpu架构,比如armv7,ar ...

  5. python脚本执行报错:SyntaxError: Non-ASCII character '\xe6' in file ip.py on line 4...

    报错信息 [root@chenbj ~]# python ip.py 192.168.1.1 File "ip.py", line 4 SyntaxError: Non-ASCII ...

  6. 【Python】Python读取文件报错:UnicodeDecodeError: 'gbk' codec can't decode byte 0x99 in position 20: illegal multibyte sequence

    环境描述 text.txt 今天的天气不错 是个皻的选择 读取文件的代码 #!/usr/bin/python #-*- coding:UTF-8 -*- f = open(r'D:\Python\Py ...

  7. Python 的print报错SyntaxError: invalid syntax

    1. #!/usr/bin/python print "hello world!" print报错:SyntaxError: Missing parentheses in call ...

  8. 执行python文件报错SyntaxError: Non-ASCII character '\xe8' in file, but no encoding declared

    在文件头部加上: # -*- coding: utf-8 -*

  9. Windows下使用pip安装python包是报错-UnicodeDecodeError: 'ascii' codec can't decode byte 0xcb in position 0

    先交待下开发环境: 操作系统:Windows 7 Python版本:2.7.9 Pip版本:6.1.1 其他环境忽略 在windows下使用pip下载python包,出现如下错误 Collecting ...

随机推荐

  1. java Date 当天时间戳处理

    1. 代码 private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss"; private static Date ...

  2. mysqli返回受影响行数

    参考链接:http://php.net/manual/en/mysqli.affected-rows.php /* update rows */ $mysqli->query("UPD ...

  3. 报错”Cannot read property 'addEventListener' of null“

    1.报错:Cannot read property 'addEventListener' of null 2.解决方案: 把代码放到window.onload=function(){...}里面,因为 ...

  4. ArcGIS Server命令行工具学习笔记

    备份命令 backup.py 参数: -u 管理员账号 -p 密码 -s 站点URL -f 备份文件的存储目录路径 -h 显示帮助 还原命令 restore.py 参数: -u 管理员账号 -p 密码 ...

  5. 阿里react整合库dva demo分析 [转]

    同,也是工作中需要,用到 dva ,  也找了些文章参考知识点. 更多:http://www.cnblogs.com/heyuqing/p/6844098.html 以下内容为摘出  mark 接着踩 ...

  6. sqlserver为数据库表增加自增字段

     需求: 数据库为SQLServer.对已有的数据库表customer加一个序号字段,一次性对所有现存客户加上编号,并在新建客户时自动增加一个编号,数值自增1. 解决方法: 1. 复制表结构.把原 ...

  7. 润乾报表如何使用Echarts

     1.    润乾报表中使用Echarts统计图的步骤 2.    报表中添加echarts2统计图 选中需要设为统计图的单元格,点击 报表-第三方图形 菜单项,或者右键菜单-第三方图形,在图形编 ...

  8. ubuntu16.04安装网易云音乐

    源网址 对于网易,我只服云音乐,业界良心,用过的人都知道.我最喜欢的就是歌曲的评论功能,还有朋友圈子.里面有很多好段子,还有很多的好故事,基本上,不是分手,就是回忆初恋,还有吐槽的.我认为音乐带给人的 ...

  9. AIX用裸设备给表空间添加数据文件

    近期在对生产数据库表空间进行扩容,目的是春节期间保证表空间的使用率,不会出现紧急告警信息. 1.查看表空间使用率的SQL语句 col tablespace_name for a16 col SUM_S ...

  10. Android笔记:解决 Your project contains error(s),please fix them before running your application问题

    解决 Your project contains error(s),please fix them before running your application问题 貌似好多人都有遇到这问题,而且网 ...