Errors and Exceptions 官方文档:https://docs.python.org/3.5/tutorial/errors.html python中所有的异常都继承自BaseException类. 1.1 Syntax Errors 1.2 Exceptions https://docs.python.org/3.5/library/exceptions.html 1.3 Handling Exception 使用try语句: >>> while True: ... t…
[译]The Python Tutorial#Errors and Exceptions 到现在为止都没有过多介绍错误信息,但是已经在一些示例中使用过错误信息.Python至少有两种类型的错误:语法错误以及异常 8.1 Syntax Errors 语法错误,也称解析错误,是Python初学者经常抱怨的问题. >>> while True print('Hello world') File "<stdin>", line 1 while True print…
Python Tutorial 学习(八)--Errors and Exceptions恢复 Errors and Exceptions 错误与异常 此前,我们还没有开始着眼于错误信息.不过如果你是一路跟着例程走过来的,你就会发现一下错误信息.在Python里面至少有两类错误:语法错误和异常(syntax errors and exceptions) 8.1. Syntax Errors 语法错误 语法错误就是语法错误,语法错误就是语法错误. 比如说,关键词拼写错误,缩进错误,标点符号错误等等,…
笔记-python-tutorial-8.errors and exceptions 1.      errors and exceptions 1.1.    syntax errors >>> while True print('Hello world') File "<stdin>", line 1 while True print('Hello world') ^ SyntaxError: invalid syntax 1.2.    异常处理 &…
Python Tutorial笔记 Python入门指南 中文版及官方英文链接: Python入门指南 (3.5.2) http://www.pythondoc.com/pythontutorial3/ Python Tutorial (3.5.2) https://docs.python.org/3/tutorial/ 2.使用Python解释器 Control-D 文件结束符,让解释器以0状态码退出,相当于exit()命令. Control-P 命令行编辑功能. 为源文件指定不同的编码: #…
笔记-python lib-pymongo 1.      开始 pymongo是python版的连接库,最新版为3.7.2. 文档地址:https://pypi.org/project/pymongo/ 使用文档:http://api.mongodb.com/python/current/tutorial.html The PyMongo distribution contains tools for interacting with MongoDB database from Python.…
[译]The Python Tutorial#More Control Flow Tools 除了刚才介绍的while语句之外,Python也从其他语言借鉴了其他流程控制语句,并做了相应改变. 4.1 if Statements 或许最广为人知的语句就是if语句了.例如: x = int(input("Please enter an integer: ")) if x < 0: x = 0 print('Negative changed to zero') elif x == 0…
I have planed to learn Python for many times. I have started to learn Python for many times . However, I can't use it fluently up to now. Now I know I was wrong. I just tried to remember the syntax and took notes on paper with little practice. Now I…
6. Modules 当你退出Python的shell模式然后又重新进入的时候,之前定义的变量,函数等都会没有了. 因此, 推荐的做法是将这些东西写入文件,并在适当的时候调用获取他们. 这就是为人所知的脚本文件. 随着编程的深入,代码的增多,你可能又会将代码存到不同的文件中方便管理. 你会想到去使用之前的编程中已经写好了的一个函数的定义. Python有自己的方式去实现这些.它会将这些保存了定义的函数,类等的文件(文件夹)称作module; 一个module中的定义的函数 类等可以被导入到另一个…
http://delphi.about.com/od/objectpascalide/a/errorexception.htm Unfortunately, building applications includes coding. Regardless of how carefully you write/debug your program, it will be impossible to imagine every situation that can go wrong. Inexpe…
笔记-python操作mysql 1.      开始 1.1.    环境准备-mysql create database db_python; use db_python; create table `t2`( `id` int unsigned auto_increment, `name` varchar(30), primary key(`id`)); #创建用户并授权 create user 'dev_python' identified by '123456'; grant all…
笔记-python异常信息输出 1.      异常信息输出 python异常捕获使用try-except-else-finally语句: 在except 语句中可以使用except as e,然后通过e得到异常信息: str(e): # 返回字符串类型,只给出异常信息,不包括异常信息的类型,如I/O的异常信息. division by zero repr(e): #给出较全的异常信息,包括异常信息的类型 ZeroDivisionError('division by zero',) e.mess…
笔记-python -asynio 1.      简介 asyncio是做什么的? asyncio is a library to write concurrent code using the async/await syntax. asyncio is used as a foundation for multiple Python asynchronous frameworks that provide high-performance network and web-servers,…
[译]The Python Tutorial#Brief Tour of the Standard Library - Part II 第二部分介绍更多满足专业编程需求的高级模块,这些模块在小型脚本中很少用到. 11.1 Output Formatting reprlib模块为大型或者深度嵌套的容器提供了一个定制版本的repr()函数: >>> import reprlib >>> reprlib.repr(set('supercalifragilisticexpial…
[译]The Python Tutorial#Brief Tour of the Standard Library 10.1 Operating System Interface os模块为与操作系统交互提供了许多函数: >>> import os >>> os.getcwd() # Return the current working directory 'C:\\Python36' >>> os.chdir('/server/accesslogs'…
[译]The Python Tutorial#Virtual Environments and Packages 12.1 Introduction Python应用经常使用不属于标准库的包和模块.应用有时会需要一个特定版本的库,因为应用可能会需要一个特定bug得到修复的库,或者应用依赖库中一个废弃版本的接口. 这意味着一个Python安装可能无法满足每个应用的需求.如果应用A依赖特定模块的1.0版本,而应用B依赖其2.0版本,那么需求就冲突了,并且安装1.0和2.0的任意一个版本都会导致其中一…
[译]The Python Tutorial#Using the Python Interpreter 2.1 Invoking the Interpreter Python解释器通常安装在目标机器的/usr/local/bin/python3.6目录下:将/usr/local/bin设置到Unix shell的搜索路径中,就可以使用以下命令: python3.6 启动Python解释器[1].由于Python的安装路径是可选的,其他目录也是可能的:可以咨询Python安装用户或者系统管理员确认…
[译]The Python Tutorial#Whetting Your Appetite 1. Whetting Your Appetite 如果你需要使用计算机做很多工作,最终会发现很多任务需要自动化.例如,在大量文本文件中搜索替换,或者以更加复杂的方式对大量图片进行重命名或者整理.也许你想要编写一个小型自定义数据库,一个特殊用途的GUI应用或者一个简单的游戏. 如果你是专业的软件开发者,可能不得不使用多个C/C++/Java库,它们的编写/编译/测试/重编译周期是如此的漫长.也许你正为这些…
[译]The Python Tutorial#Input and Output Python中有多种展示程序输出的方式:数据可以以人类可读的方式打印出来,也可以输出到文件中以后使用.本章节将会详细讨论. 7.1 Fancier Output Formatting 目前为止已经介绍过两种输出值的方式:表达式语句和print()函数.(第三种方式是使用对象的write()方法:使用sys.stdout引用标准输出文件.详细信息参考库文件参考手册.) 有时候需要对输出有更多的控制,而不是简单的使用空格…
笔记-python tutorial-9.classes 1.      Classes 1.1.    scopes and namespaces namespace: A namespace is a mapping from names to objects. 典型的命名空间有:built-in names;the global names in a module; the local names in a function. 两个命名空间中的名称之间没有任何关系,例如两个模块可以都定义一…
[译]The Python Tutorial#Data Structures 5.1 Data Structures 本章节详细介绍之前介绍过的一些内容,并且也会介绍一些新的内容. 5.1 More on Lists 列表数据类型拥有更多方法,以下是列表对象的所有方法: list.append(x) 在列表末尾添加新项,等同于a[len(a):] = [x] list.extend(iterable) 添加可迭代对象中所有的项来扩展列表,等同于a[len(a):] = iterable list…
[译]The Python Tutorial#Modules 6. Modules 如果你从Python解释器中退出然后重新进入,之前定义的名字(函数和变量)都丢失了.因此,如果你想写长一点的程序,使用文本编辑器来准备解释器的输入会更好,使用文件作为替代的输入.这也被称作创建脚本.当程序越来越长时,出于易于维护的原因,你可能会将程序分割为几个文件.你也可能想要在多个程序中使用很好用的一个函数,而不用将其定义拷贝到每一个程序中. 为了支持这些需求,Python提供了将定义放入一个文件的方式,并且在…
写在前面 本篇文章是<The Python Tutorial>(3.6.1),第九章,类的译文. 9. Classes 与其他编程语言相比,Python的类机制定义类时,最小化了新的语法和语义的引入.Python类机制是C++和Modula-3的混合体.Python类支持所有面向对象编程的特性: 类继承机制允许多继承,子类可以覆盖其父类们的任何方法,方法可以使用相同的名字调用父类中的方法.对象可以包含任意数量和类型的数据. 跟模块相似,Python类也具有Python的动态性质: 类在运行时被…
Laravel API Errors and Exceptions: How to Return Responses February 13, 2019 API-based projects are more and more popular, and they are pretty easy to create in Laravel. But one topic is less talked about – it’s error handling for various exceptions.…
看到了中文版的python tutorial,发现是网页版的,刚好最近在学习爬虫,想着不如抓取到本地 首先是网页的内容 查看网页源码后发现可以使用BeautifulSoup来获取文档的标题和内容,并保存为doc文件. 这里需要使用from bs4 import BeautifulSoup 来导入该模块 具体代码如下: # 输出所在网址的内容from bs4 import BeautifulSoup def introduce(url): res = requests.get(url) res.e…
最近在学习过程中发现opencv有了很多变动, OpenCV 官方的 Python tutorial目前好像还没有改过来,导致大家在学习上面都出现了一些问题,现在做一个小小的罗列,希望对大家有用 做的是关于全景图像的拼接,关于sift和surf的语法之后有需要会另开文章具体阐述,此篇主要是解决大家困惑许久的问题. 笔者python3.x 首先是安装上,必须先后安装pip install opencv_python和pip install opencv-contrib-python==3.3.0.…
链接: The Python Tutorial : https://docs.python.org/3.6/tutorial/index.html Documentation: https://docs.python.org/3.6/index.html The Python Standard Library¶:  https://docs.python.org/3.6/library/index.html 1.  升级pip pip install --upgrade2 安装PIL库pip3…
MongoDB学习笔记:Python 操作MongoDB   Pymongo 安装 安装pymongopip install pymongoPyMongo是驱动程序,使python程序能够使用Mongodb数据库,使用python编写而成: 数据库相关操作 连接及创建数据库 import pymongo connect = pymongo.MongoClient("mongodb://localhost:27017/") mydb = connect ["test"…
语法错误 语法错误又被称解析错误 >>> for i in range(1..10):print(i) File "<stdin>", line 1 for i in range(1..10):print(i) ^ SyntaxError: invalid syntax 语法分析器指出错误行,并且在检测到错误的位置前面显示一个小“箭头”. 错误是由箭头 前面 的标记引起的(或者至少是这么检测的) 异常 即使一条语句或表达式在语法上是正确的,当试图执行它时也…
1. python中的try{}catch{} 2. raise exception 3. try...except ... else.. 4. finally块 python中的异常处理的keyword和c#中的是不同样的,python中使用try,except关键在来处理异常,例如以下: 2. raise excepption python中假设在except中假设须要将异常又一次抛出能够使用keywordraise,类似于c#中的throwkeyword. It is useful for…