易截截图软件、单文件、免安装、纯绿色、仅160KB
热门标签: c c# c++ asp asp.net linux php jsp java vb Python Ruby mysql sql access Sqlite sqlserver delphi javascript Oracle ajax wap mssql html css flash flex dreamweaver xml
 最新文章 : Python

Python and MySQL

 近来需要用Python对MySQL数据库进行操作。Python久闻其名,未见其“人”;数据库曾经很高分,早已还给先生,更无MySQL经验。于是一切从零开始,借机好好学习一番。
Python这个脚本语言确实名副其实,用了几天便喜欢上它啦。很简洁,很方便。以缩减作为模块分割符,读起来赏心悦目。python的内建数据类型(list, tuple, dict)以及内存管理机制使得变量的使用非常简单,写起代码来酣畅淋漓(当然还是应该动手前自个进行规划的好)。
关键的,Python已经流行了很久啦,各种模块很多很强大。比如其MySQL接口。利用Python,很容易的就将一些复杂的SQL过程重新实现了。实在不错。
数据库这边主要复习了下关系数据的相关概念,了解一些MySQL的具体语法和命令。因为主要是操作,暂时不涉及数据库的设计,就不多说了。感慨一下,数据库真是互联网公司的核心之一。
几个不错的参考文档:
Python:
《Python核心编程》
http://docs.python.org/tutorial/index.html
MySQL:
《数据库系统概念》
http://dev.mysql.com/doc/refman/5.1/zh/index.html
Python and MySQL:
http://www.kitebird.com/articles/pydbapi.html
http://mysql-python.sourceforge.net ......

Installing Python 安装Python


   
You are here: Home ‣ Dive Into Python 3 ‣
Difficulty level: ♦♢♢♢♢
Installing Python 安装Python
❝ Tempora mutantur nos et mutamur in illis. (Times change, and we change with them.) ❞
— ancient Roman proverb
 
Diving In
Welcome to Python 3. Let's dive in. In this chapter, you'll install the version of Python 3 that's right for you.
Which Python Is Right For You?  哪个版本适合你
The first thing you need to do with Python is install it. Or do you?
If you're using an account on a hosted server, your ISP may have already installed Python 3. If you’re running Linux at home, you may already have Python 3, too. Most popular GNU/Linux distributions come with Python 2 in the default installation; a small but growing number of distributions also include Python 3. Mac OS X includes a command-line version of Python 2, but as of this writing it does not include Python 3. Microsoft Windows does no ......

Python sqlite3和单元测试

 
import os
import unittest # 包含单元测试模块
import sqlite3 as sqlite # 包含sqlite3模块
def get_db_path():
return "sqlite_testdb"
class TransactionTests(unittest.TestCase): # 单元测试第一步: 由TestCase派生类
def setUp(self): # 单元测试环境配置
try:
os.remove(get_db_path())
except:
pass
self.con1 = sqlite.connect(get_db_path(), timeout=0.1) # 连接数据库
self.cur1 = self.con1.cursor() # 获取游标
self.con2 = sqlite.connect(get_db_path(), timeout=0.1)
self.cur2 = self.con2.cursor()
def tearDown(self): # 单元测试环境清除
self.cur1.close() # 关闭游标
self.con1.close() # 关闭连接
self.cur2.close()
self.con2.close()
os.unlink(get_db_path())
def CheckDMLdoesAutoCommitBefore(self):
self.cur1.execute("create table test(i)") # 执行SQL查询
self.cur1.execute("insert into test(i) values (5 ......

Python sqlite3和单元测试

 
import os
import unittest # 包含单元测试模块
import sqlite3 as sqlite # 包含sqlite3模块
def get_db_path():
return "sqlite_testdb"
class TransactionTests(unittest.TestCase): # 单元测试第一步: 由TestCase派生类
def setUp(self): # 单元测试环境配置
try:
os.remove(get_db_path())
except:
pass
self.con1 = sqlite.connect(get_db_path(), timeout=0.1) # 连接数据库
self.cur1 = self.con1.cursor() # 获取游标
self.con2 = sqlite.connect(get_db_path(), timeout=0.1)
self.cur2 = self.con2.cursor()
def tearDown(self): # 单元测试环境清除
self.cur1.close() # 关闭游标
self.con1.close() # 关闭连接
self.cur2.close()
self.con2.close()
os.unlink(get_db_path())
def CheckDMLdoesAutoCommitBefore(self):
self.cur1.execute("create table test(i)") # 执行SQL查询
self.cur1.execute("insert into test(i) values (5 ......

Python多线程知识点


知识点
1.线程是“轻量级”进程,因为相较于进程的创建和管理,操作系统通常会用较少的资源来创建和管理线程。操作系统要为新建的进程分配单独的内在空间和数据;相反,程序中的线程在相同的内存空间中执行,并共享许多相同的资源。多线程程序在结内存的使用效率要优于多进程程序。
2.python提供了完整的多线程处理类,如果操作系统支持多线程,就可用python的threading模块创建多线程应用程序。程序员可以在一个应用程序中包含多个执行线程,而且每个线程都表明程序中的一部份要与其他线程并发执行。许多应用程序都可获益于多线程编程。Web浏览器下载大文件时(比如音乐或视频),用户希望立即可欣赏音乐或观看视频,这样就可以让一个线程下载,另一个线程播放已经下载的一部分。从而实现多个操作并发执行。
性能提示
1.单线程程序问题在于要在结束费时较长的操作后,才能开始其它操作。而在多线程程序中,线程可共享一个或多个处理器,使多个任务并行执行。
2.解释器开始执行程序时,“主”线程开始执行。每个线程都可创建和启动其它线程。如果程序包含多个正在运行的线程,它们将依据指定的间隔时间(称为一个quantum),依次进入和离开解释器。Pyt ......

Python有用的模块

http://chardet.feedparser.org/  自动检测编码
http://effbot.org/zone/celementtree.htm  cElementTree
http://github.com/jaybaird/python-bloomfilter bloomfilter
http://docs.python.org/library/threading.html#threading.activeCount threading ......

Python 线程操作

在python中如何创建一个线程对象
如果你要创建一个线程对象,很简单,只要你的类继承threading.Thread,然后在__init__里首先调用threading.Thread的__init__方法即可
import threading
class mythread(threading.Thread):
    def __init__(self, threadname):
        threading.Thread.__init__(self, name = threadname)
....
这才仅仅是个空线程,我可不是要他拉空车的,他可得给我干点实在活。很简单,重写类的run()方法即可,把你要在线程执行时做的事情都放到里面
import threading
import time
class mythread(threading.Thread):
    def __init__(...):
    ....
    def run(self):
        for i in range(10):
        print self.getName, i
        time.sleep(1)
以上代码我们让这个线程在执行之后每隔1秒输出一次信息到屏幕,10次后结束
getName()是threading.Thread类的一个方法,用来获得这个线程对象的name。还有一个方 ......
总记录数:695; 总页数:116; 每页6 条; 首页 上一页 [79] [80] [81] [82] 83 [84] [85] [86] [87] [88]  下一页 尾页
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号