《Head First Python》笔记 第九章 管理你的数据

这章省略太多,由于对前面的代码修改了不少,主要将数据处理移到使用数据库,后面学完再回头来看。web

9. Manage Your Data: Handling Input

在此输入图片描述

利用Python的数据库API

“数据库API” —— 这是一种标准化机制,用于从Python程序访问一个基于SQL的数据库系统。sql

(看起来比JDBC容易使用。)数据库

不论使用的后台数据库是什么,代码所遵循的过程都是同样的:code

链接 -> 建立(游标) -> 交互 -> 提交或回滚 -> 关闭(链接)server

在此输入图片描述

数据库API的相应Python代码

经常使用代码:sqlite

在此输入图片描述

Python包括SQLite图片

在此输入图片描述

The fieldStorage() method from the standard library’s cgi module lets you access data sent to your web server from within your CGI script.ip

The standard os library includes the environ dictionary providing convenient access to your program’s environment settings.it

The SQLite database system is included within Python as the sqlite3 standard library.io

The connect() method establishes a connection to your database file.

The cursor() method lets you communicate with your database via an existing connection.

The execute() method lets you send an SQL query to your database via an existing cursor.

The commit() method makes changes to your database permanent.

The rollback() method cancels any pending changes to your data.

The close() method closes an existing connection to your database.

The “?” placeholder lets you parameterize SQL statements within your Python code.

相关文章
相关标签/搜索