错误是多种多样的,在 except 语句中,可以捕获指定的异常 修改代码如下: import io path = r'' mode = 'w' try: file = open(path,mode) str = file.read() print(str) except FileNotFoundError as e: print(e) except io.UnsupportedOperation as e: print(e) finally: print('end') 那么,现在只有在 path…
http://www.cnblogs.com/BeginMan/p/3171977.html 一.什么是函数.方法.过程 推荐阅读:http://www.cnblogs.com/snandy/archive/2011/08/29/2153871.html 一般程序设计语言包含两种基本的抽象:过程抽象和数据抽象.过程抽象有时也称控制抽象. 子程序在1950年以前就发明了,作为一种抽象那时候并未被完全接受.相反,最初它被看做是一种节省代码的机制,但很快子程序就被认可为过程抽象的一种方式.意识到子程序…
Python使用Mysql过程中一些错误 ssh登录远程服务器 ssh ubuntu@xxx.xxx.xx.xx 第一:ubuntu终端中登录Mysql mysql -uroot -p 然后输入密码即可在本地终端中登录mysql 第一:Mysql ERROR 1045 (28000): Access denied for user 'root'@'localhost' 这是ubuntu中安装Mysql过程没有设置密码,导致无法登录 mysql -uroot -p use mysql; updat…
figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max-width: 100%; vertical-align: middle; } button, input, select, textarea { color: inherit; font: inherit; } input[type="checkbox"], input[type=&quo…
figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max-width: 100%; vertical-align: middle; } button, input, select, textarea { color: inherit; font: inherit; } input[type="checkbox"], input[type=&quo…
虽然叫错误,但跟 C# 中的异常是一回事.只不过 Python 中叫错误(Error)而 C# 中叫异常(Exception). 先手工产生一个异常: file = open('','r') 上面一句由于路径是空路径,因此文件肯定是不存在的,执行这一句会引发 FileNotFoundError 这个错误. 既然是错误的,程序也停止了,这是我们不希望的,因此得想办法处理一下. 在 Python 中,异常处理使用 try.except.finally 这三个关键字. 修改代码如下: path = '…
今天学习了Python中有关正则表达式的知识.关于正则表达式的语法,不作过多解释,网上有许多学习的资料.这里主要介绍Python中常用的正则表达式处理函数. re.match re.match 尝试从字符串的开始匹配一个模式,如:下面的例子匹配第一个单词. import re text ="JGood is a handsome boy, he is cool, clever, and so on..." m = re.match(r"(\w+)\s", text)…
实际开发中,我们会经常用到数据库. Python里对数据库的操作API都很统一. SQLite SQLite是一种嵌入式数据库,它的数据库就是一个文件.由于SQLite本身是C写的,而且体积很小,所以,经常被集成到各种应用程序中,甚至在iOS和Android的App中都可以集成. Python内置了sqlite3. #coding:utf-8 import sqlite3 conn = sqlite3.connect('test.db') cursor = conn.cursor() # sql…
一. Python介绍 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏姆为了在阿姆斯特丹打发时间,决心开发一个新的脚本解释程序,作为ABC语言的一种继承. 最新的TIOBE排行榜,Python赶超C#占据第四, Python崇尚优美.清晰.简单,是一个优秀并广泛使用的语言. 由上图可见,Python整体呈上升趋势,反映出Python应用越来越广泛并且也逐渐得到业内的认可!!! Python可以应用于众多领域,如:数据分析.组件集成.…
figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max-width: 100%; vertical-align: middle; } button, input, select, textarea { color: inherit; font: inherit; } input[type="checkbox"], input[type=&quo…