8th Chapter Anomalies
8.1 What is an exception
>>> 1/0
Traceback (most recent call last):File "", line 1, in 1/0Zerodivisionerror:integer division or modulo by zero
8.2 Error in your own way
8.2.1 Raise statement>>> Raise Exception
Traceback (most
#-*-coding:utf-8-*-import mysql from MySQL import connector user = ' root ' pwd = ' 123456 ' host = ' 127.0.0.1 ' port = ' 3306 ' db = ' springmvc ' # money Transfer Class class TransferMoney (Object): # constructor def __init__ (self, conn):
First, install the PostgreSQL modulePip Install PSYCOPG2Sometimes it will fail, install more than 2 times (I succeeded the second time).Second, the database connection interfaceBecause Python unifies the interface of the database connection, PSYCOPG2
The adorner in Python is a very useful thing, and we can write some specific methods and common methods into a decorator, which provides a great convenience for invoking these methods, thus improving the readability and simplicity of our code, as
Preface
In the development of an application system, from top to bottom generally need four components: client-business Logic Layer-data access layer-database, where the data access layer is a bottom-level, core technology. And in the actual
1. python implements the Stack. You can first write the stack class to the file stack. py, use from Stack import Stack in other program files, and then use the stack. The stack. py program is as follows:
Class Stack (): def _ init _ (self, size):
Before a Python package dbutils and Pymysql wrote a basedao.py, in recent days and re-organized the next thoughts, optimized the next basedao.py, the current support methods are not many, follow-up will be improved, add.
Main functions:
1. Querying
This article mainly describes the Python implementation of the stack and queue method, including the stack and queue definition methods and common operations, with a certain reference value, the need for friends can refer to the following
The
This article describes how to handle exceptions in Python. This article describes how to detect exceptions in try-retry T and how to use the context manager (... As... Statement), raise raises exceptions, assertions, and so on. For more information,
Python multi-decoration, python Decoration
Multiple decorators are used to modify the same object]
1. the decorator has no parameters:
1 >>> def first(func): 2 print '%s() was post to first()'%func.func_name 3 def _first(*args,**kw): 4
Implement a simple bank transfer operation based on Python, and implement bank transfer through python
Preface
During the development of an application system, four components are required from top to bottom: client-business logic layer-data access
Exception what is an exceptionPython uses an exception object to represent an exception condition. An exception is thrown when an error is encountered. Assuming that the exception object is not handled or captured, the program terminates its
This article illustrates how Python implements stacks and queues. Share to everyone for your reference. The specific analysis is as follows:
1, Python implementation stack, you can first write the stack class file stack.py, in other program files
The python exception handling mechanism is similar to Java, using the try-except-finally structure.Try-except Detecting anomaliesFormattry: try_statementexcept (ErrorType1, ErrorType2),e: handle_statementfinally: finally_statementInstance#!/
Multiple adorners, that is, multiple adorners to modify the same object "actually not exactly, and look at the following detailed"
1. The adorner has no parameters:
Copy Code code as follows:
>>> def A (func):
print '%s ' () is post
The python exception handling mechanism is similar to Java, using a try-except-finally structure.
Try-except Detection exception
Format
Copy Code code as follows:
Try
Try_statement
Except (ErrorType1, ErrorType2), E:
Exception in notes of python basic tutorial, and python basic tutorial
Errors in your own way
When a raise statement is used to raise an Exception, you can use a class (which should be a subclass of Exception) or an instance parameter as the
Implemented a simple version of the Logging.config, support the general configuration through the config file.
There is a better way to feel, and it is to use the Logging.config.fileConfig (Log_config_file) method to read it and modify it by
A data structure is a structure used to organize data together. In other words, data structures are used to store a series of associated data. There are four built-in data structures in Python: List, Tuple, Dictionary, and Set. This document
Multiple adorners, that is, multiple adorners decorate the same object "It's not exactly the same, and look at the details below."
1. Adorner no parameters:Copy the Code code as follows:
>>> def First (func):
print '%s () was post to first ()
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.