python 问题总结
-
SyntaxError: (unicode error) 'utf-8' codec can't decode byte 原因:输出了中文 解决: 编辑器是UE, 默认的编码不是utf-8, 按F12, 选择Format改为utf-8
-
print "hello" 在python2里才被支持,在python里报错
-
NameError: name 'raw_input' is not defined python3输入用input(),之前版本用raw_input()
4.编辑器 pyCharm http://blog.csdn.net/u013088062/article/details/50249751 快捷键 1、Ctrl + Enter:在下方新建行但不移动光标; 2、Shift + Enter:在下方新建行并移到新行行首; 3、Ctrl + /:注释(取消注释)选择的行; 4、Ctrl + Alt + L:格式化代码(与QQ锁定热键冲突,关闭QQ的热键); 5、Ctrl + Shift + +:展开所有的代码块; 6、Ctrl + Shift + -:收缩所有的代码块; 7、Ctrl + Alt + I:自动缩进行; 8、Alt + Enter:优化代码,添加包; 9、Ctrl + Shift + F:高级查找; 10、Alt + Shift + Q:更新代码到远程服务器;
5.Python 保留字符
下面的列表显示了在Python中的保留字。这些保留字不能用作常数或变数,或任何其他标识符名称。
所有 Python 的关键字只包含小写字母。 and exec not assert finally or break for pass class from print continue global raise def if return del import try elif in while else is with except lambda yield
5.关于python标识符 (1)以单下划线开头 _foo 的代表不能直接访问的类属性,需通过类提供的接口进行访问,不能用 from xxx import * 而导入 (2)以双下划线开头的 __foo 代表类的私有成员; (3)以双下划线开头和结尾的 foo 代表 Python 里特殊方法专用的标识,如 init() 代表类的构造函数。
6.module 可以定义在包里面.Python 定义包的方式稍微有点古怪,假设我们有一个parent 文件夹,该文 件夹有一个child 子文件夹.child 中有一个module a.py . 如何让Python 知道这个文件层次结构?很简 单,每个目录都放一个名为_init_.py 的文件.该文件内容可以为空.这个层次结构如下所示 parent --_init.py --child -- _init.py --a.py b.py
from parent.child.a import add_func
7.PyCharm安装第三方库方法 file --> settings -->project:pythonproject --> project Interpretor -->点击右上角的+号, 然后在搜索框中搜索需要安装的第三方库(此处搜索requests)然后点击界面左下角的Install Package进行安装即可。
PIL 安装 pip install pillow
-
python 图像识别 pip install PIL pip install pytesseract 安装tesseract-ocr时需要 visual C++ 14+ http://landinghub.visualstudio.com/visual-cpp-build-from PIL import Image import pytesseract text=pytesseract.image_to_string(Image.open('denggao.jpeg'),lang='chi_sim') print(text
-
打包为exe pip install pyinstaller pyinstall hello.py http://blog.csdn.net/zt_xcyk/article/details/73786659?locationNum=9&fps=1
10.python win32gui 查找win窗口 http://blog.csdn.net/liuyukuan/article/details/52975730
- 关于第三方库的自动提示方法变量, 使用注解注释本地变量
type: 对应的类型
im = Image.open('d:/ddz2.png', 'r') # type: Image.Image
- args:输入数据长度不确定,通过args将任意长度的参数传递给函数,(输出字典) def show(*args): for i in args: print(i)
show('chen','hang','wang','yadan') #============================================= chen hang wang yadan
- **kargs:输入数据长度不确定,系统自动将任意长度参数用dict(字典)表示
def show(**kargs): for i in kargs.items(): print(i)
show(name='hangge',age=25,sex='man',school='wust') #============================================ ('name', 'hangge') ('school', 'wust') ('sex', 'man') ('age', 25)
14.Pyplot 绘制图表 https://zhuanlan.zhihu.com/p/28048062