对数据库的操作基本分为三步:
连接数据库
根据需要执行SQL语句,接受返回值
关闭连接
我们正常的数据库应该都离不开这三步,下来说说如何使用python中的MySQLdb模块进行这些操作:
首先,我们需要把MySQLdb引入到程序中
import MySQLdb
然后开始数据库操作
1.数据库连接
conn = MySQLdb.connect(host="localhost", port=3306, user="root", passwd="sa", db="test")
通过connect函数与数据库建立连接,返回连接对象,用来进行数据库的操作
host:数据库主机名,默认是localhost
port:mysql服务器使用的TCP端口,默认是3306
user:数据库登录用户名,默认是当前用户
passwd:数据库登录密码,默认为空
db:将要使用的数据库名,将对改数据库进行操作,无默认值
这个连接对象通过下面的两个函数对事务的操作:
commit() 提交
rollback() 回滚
2.执行sql和接受返回值
cursor=conn.cursor()
n=cursor.execute(sql,param)
首先,我们用使用连接对象获得一个cursor对象,接下来,我们会使用cursor提供的方法来进行工作.这些方法包括两大类:
1.执行命令,2 ......
python 中的re 模块
正则表达式
就个人而言,主要用它来做一些复杂字符串分析,提取想要的信息
学习原则:够用就行,需要的时候在深入
现总结如下:
正则表达式中特殊的符号:
“.” 表任意字符
“^ ” 表string起始
“$” 表string 结束
“*” “+” “?” 跟在字符后面表示,0个——多个, 1个——多个, 0个或者1个
*?, +?, ?? 符合条件的情况下,匹配的尽可能少//限制*,+,?匹配的贪婪性
{m} 匹配此前的字符,重复m次
{m,n} m到n次,m,n可以省略
举个例子 ‘a.*b’ 表示a开始,b结束的任意字符串
a{5} 匹配连续5个a
[] 表一系列字符 [abcd] 表a,b,c,d [^a] 表示非a
| A|B 表示A或者B , AB为任意的正则表达式 另外|是非贪婪的如果A匹配,则不找B
(…) 这个括号的作用要结合实例才能理解, 用于提取信息
\d [0-9]
\D 非 \d
\s 表示空字符
\S 非空字符
\w [a-zA-Z0-9_]
\W 非 \w
一:re的几个函数
1: compile(pattern, [flags])
根据正则表达式字符串 pattern 和可选的flags 生成正则表达式 对象
生成正则表达式 对 ......
require 'win32ole'
excel = WIN32OLE::new('excel.Application')
workbook = excel.Workbooks.Open('E:\RubyApp\bmk.xls')
worksheet = workbook.Worksheets(1) #get hold of the first worksheet
worksheet.Select #bring it to the front -need sometimes to run macros, not for working with a worksheet from ruby
#excel['Visible'] = true #make visible, set to false to make invisible again. Don't need it to be visible for script to work
#value1=worksheet.Range('a12')['Value'] #get value of single cell
#puts value1
#data = worksheet.Range('a1:c12')['Value'] #read into 2D array
#data.each do |data1|
#data1.each do |data2|
#puts data2
#end
#end
line = '1'
while worksheet.Range("c#{line}")['Value']
line.succ!
end #line now holds row number of first empty row
puts line
#i=3
#puts worksheet.cells(i-1,1).text[8,16].to_i+1
#处理准考证号,让它自动增加
#while i < line.to_i
for i in 3...line.to_i
worksheet.cells(i,1).value="00320501"+(worksh ......
1、VSS客户端打开工程时提示 Access to file"\\***\rights.dat" denied
该提示是指没有网络访问的权限,用户要在共享文件夹有可写的权限才可以。我们在设置共享文件的时候应该允许写入。
2、为VSS设置环境变量
默认情况下我们每次打开VSS客户端填充的用户名都是当前系统登陆的用户,这样使用起来很不方便。我们可以设置一个环境变量SSUSER来指定打开VSS客户端时的用户名
注意:在Windows2003中设置共享的写入权限有两个地方需要设置everyone的写入权限。
第一:在文件夹的 属性-》安全 加入Everyone的写入权限;
第二:在文件夹的 属性-》共享-》权限 设置Everyone的“更改”权限“;
只有通过这样两上步的设置才能使一个目录能让任何人写入! ......
Failed to access IIS metabase.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.Hosting.HostingEnvironmentException: Failed to access IIS metabase.
The process account used to run ASP.NET must have read access to the IIS metabase (e.g. IIS://servername/W3SVC). For information on modifying metabase permissions, please see http://support.microsoft.com/?kbid=267904.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[HostingEnvironmentException: Failed to access IIS metabase.]
System.Web.Configuration.MetabaseServerConfig.MapPathCaching(String siteID, VirtualPath path) +3500426
System.Web.Configuration.MetabaseSer ......
OS X自从10.4后把SQLite这套相当出名的数据库软件,放进了作业系统工具集里。OS X包装的是第三版的SQLite,又称SQLite3。这套软件有几个特色:
软件属于公共财(public domain),SQLite可说是某种「美德软件」(virtueware),作者本人放弃着作权,而给使用SQLite的人以下的「祝福」(blessing):
May you do good and not evil. 愿你行善莫行恶
May you find forgiveness for yourself and forgive others. 愿你原谅自己宽恕他人
May you share freely, never taking more than you give. 愿你宽心与人分享,所取不多于你所施予
支援大多数的SQL指令(下面会简单介绍)。
一个档案就是一个数据库。不需要安装数据库服务器软件。
完整的Unicode支援(因此没有跨语系的问题)。
速度很快。
目
前在OS X
10.4里,SQLite是以/usr/bin/sqlite3的形式包装,也就说这是一个命令列工具,必须先从终端机(Terminal.app或其他
程序)进入shell之后才能使用。网络上有一些息协助使用SQLite的视觉化工具,但似乎都没有像CocoaMySQL(配合MySQL数据库使用)
那般好用。或许随时有惊喜也未可知,以下仅介绍命令列的操作方式。
SQLite顾名思议是以SQL为基础的数据库软件, ......