如果没有安装python mysqldb模块的话会报错,“ImportError: No module named MySQLdb”

"安装python

执行 ~ yum -y install yum install MySQL-python.x86_64

如下图
2

3

python代码
#!/usr/bin/env python
import MySQLdb

try:
    conn=MySQLdb.connect(host='127.0.0.1',user='root',passwd='',db='blog',port=3306)
    cur=conn.cursor()
    a = cur.execute('select * from blog_user')
    #输出
    numrows = int(cur.rowcount)
    for i in range(numrows):
        row = cur.fetchone()
        print row

    cur.close()
    conn.close()
except MySQLdb.Error,e:
     print "Mysql Error %d: %s" % (e.args[0], e.args[1]

另附(windows下python mysqldb 模块下载地址):http://sourceforge.net/projects/mysql-python/files/mysql-python/[/warning]

python清空文件夹下log文件

#!/usr/bin/python import os import sys files_list = [] def print_files(path): lsdir = os.listdir(path) dirs = [i for i in lsdir if os.path...

阅读全文

python paramiko(SFTP) 相关文档

python paramiko SFTP文档地址: http://docs.paramiko.org/en/2.4/api/sftp.html import paramiko host = "THEHOST.com" #...

阅读全文

python 执行cmd命令并获取pid

process = subprocess.Popen('cmd命令') pid = process.pid print(pid)

阅读全文

欢迎留言