Bottle实例Todo-List—用SQLite3创建数据库

代码如下:

 Python Code 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# -*- coding:  utf-8 -*-
#!/usr/bin/python
# filename: creat_db.py
# codedtime: 2014-8-26 22:33:58

import sqlite3

#警告: todo.db文件被创建到当前目录下
con = sqlite3.connect( 'todo.db')

con.execute( "CREATE TABLE todo (id INTEGER PRIMARY KEY, task char(100) NOT NULL, status bool NOT NULL)")
con.execute( "INSERT INTO todo (task,status) VALUES\
                         ( 'Read A-byte-of-python to get a good introduction into Python', 0) ")
con.execute( "INSERT INTO todo (task,status) VALUES\
                         ( 'Visit the Python website', 1) ")
con.execute( "INSERT INTO todo (task,status) VALUES\
                        ( 'Test various editors for and check the syntax highlighting', 1) ")
con.execute( "INSERT INTO todo (task,status) VALUES\
                        ( 'Choose your favorite WSGI-Framework', 0) ")

con.commit()
在IDLE下F5运行会本目录下生成一个叫todo.db的数据库文件,有三个字段:id、task、status;这个数据库将在以后的程序中用到。







  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值