python3 5之mysql擴充套件

2022-04-30 15:18:14 字數 885 閱讀 9054

最近在學習廖雪峰的python3的教程,這是官方建議大家想學習python的同學可以去看看,真的是在網上能找到的最好文字教程,沒有之一

在廖老實講到使用python3擴充套件mysql這部分的時候,按照原文使用pip install mysql-connector-python --allow-external mysql-connector-python

命令遇到錯誤

could not find a version that satisfies the requirement mysql-connector-python (from versions: )

no matching distribution found for mysql-connector-python

遇到這個錯誤百思不得其解,單下面的童鞋也沒有發現有什麼比較好的建議,於是在網上漫無目的的尋找,花了接近四個小時,終於讓我的python3.5成功的擴充套件上mysql驅動

$ python3 setup.py build

$ python3 setup.py install

寫個指令碼

#!/usr/local/bin/python3

# -*- coding: utf-8 -*-

import mysqldb

conn = mysqldb.connect("localhost","root","root","test")

cursor = conn.cursor()

cursor.execute("select version()")

data = cursor.fetchone()

print(data);

conn.close();

使用方法和2.7的擴充套件庫一樣

python 3 5 學習筆記

字串方法 msg this is message msg.title 首字母大寫 msg.lower 字串全部小寫 msg.upper 字串全部大寫 msg.rstrip 刪除字串前後的空格 msg.lstrip 刪除字串前面的空格 msg.strip 刪除字串後面的空格 str msg 將msg轉...

Python3 5 裝飾器之案例剖析

usr bin env python coding utf 8 author zhengzhengliu 高階函式 巢狀函式 裝飾器 import time def timer func timer test1 func test1 def decor start time time.time fu...

python 3 5 爬蟲日記2

from urllib import request 輸入正規表示式模組 import re page 1 url r request.request url r.add header user agent abc 讀取首頁原碼並命名為content content request.urlopen ...