对于数据库操作,和 TCP/IP 的三次握手异曲同工之妙,建立连接,执行操作,断开连接。当然这就需要建立连接的工具
Python连接mysql的方案有oursql、PyMySQL、 myconnpy、MySQL Connector 等,不过本篇说的确是另外一个类库MySQLdb,MySQLdb 是用于Python链接Mysql数据库的接口,它实现了 Python 数据库 API 规范 V2.0,基于 MySQL C API 上建立的。
Reference
对于数据库操作,和 TCP/IP 的三次握手异曲同工之妙,建立连接,执行操作,断开连接。当然这就需要建立连接的工具
Python连接mysql的方案有oursql、PyMySQL、 myconnpy、MySQL Connector 等,不过本篇说的确是另外一个类库MySQLdb,MySQLdb 是用于Python链接Mysql数据库的接口,它实现了 Python 数据库 API 规范 V2.0,基于 MySQL C API 上建立的。
Reference
I use SELECT COUNT(*) FROM db WHERE <expression> to see if a set of records is null. So:
>>> cnt = c.fetchone() >>> print cnt (0L,)
My question is: how do you test for this condition?
I have a number of other ways to accomplish this. Is something like the following possible?
if cnt==(0L,): # do something...
MySQL-python (1.2.5) >>> import MySQLdb Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/Python2.7.3/lib/python2.7/site-packages/MySQLdb/__init__.py", line 19, in <module> import _mysql ImportError: libmysqlclient.so.18: cannot open shared object file: No such file or directory...
#!/usr/bin/python # -*- coding:utf-8 -*- import smtplib from email.mime.text import MIMEText to = ['zfsu'] cc = ['zfsu','root'] bcc = ['jack'] from_addr = 'root' message_subject = "Say Hello" message_text = "Hello world" message = "From: %s\r\n" % from_addr \ + "To: %s\r\n" % "...
Puppet Language Style Guide: Version 2.0.1Puppet: Version 3.7+
(Note: While the style guide maps to Puppet 3.7, many of its recommendations apply to Puppet 3.0.x and up.)
The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “...
I recommend that you use the standard packages email and smtplib together to send Email. Please look at the following example (reproduced from the Python documentation). Notice that if you follow this approach, the "simple" task is indeed simple, and the more complex tasks (like attaching binary objects or send...
问题描述:
最近发现自动发送工作日报的那个脚本出现了问题, 发送是大昨天的内容.
可能是系统时间或是服务器时间配置不正确,下面开始逐步排查.
^_^[11:04:26][root@master01 ~]#date Thu Oct 22 11:05:33 CST 2015 ^_^[11:05:33][root@master01 ~]#cat /etc/sysconfig/clock ZONE="Asia/Shanghai" #UTC=true #ARC=false <?php //date_default_timezone_set('UTC'); date_default_timezone_set('CST/8.0'); $today...
前言:
很多时候我们会用到python去调用外部工具/命令去实现某种功能。
I. os
https://docs.python.org/2/library/os.html
os.system
执行流程
system(command) -> exit_status
Execute the command (a string) in a subshell.
# os.system() 是新起一个shell去干活的,对系统的开销比较大
# 仅在一个子终端运行系统命令...