【置頂】知識點彙總

一、Python操做mysql  MySQLdbpython

格式:
import MySQLdb
conn = MySQLdb.connect(host='',user='',passwd='',db='') # 伸出手
cur=conn.cursor()  # 打開門

業務代碼
一、增刪改查
  增、刪、改 須要conn.commit() 
二、一次插入多個值
  li=[
   ('a',11),
   ('b',22),
  ]
      cur.executemany()
三、帶字段顯示
  cur=conn.cursor(cursorclass=MySQLdb.cursors.DictCursor) # 加上 cursorclass=MySQLdb.cursors.DictCursor,不要字段就不加這個便可

cur.close()   # 收回手
conn.close()  # 關上門

 二、反射mysql

'''
以字符串的形式導入模塊
以字符串的形式執行函數
'''

#!/usr/bin/env python
#_*_ coding:utf8 _*_sql

 
 

def Foo():
print('foo is fun!')函數

#!/usr/bin/env python
#_*_ coding:utf8 _*_url


tmp='test'
fun='Foo'spa

module = __import__(tmp)
Fun=getattr(module,fun)
Fun()code


eg:
 
           func()
defrun():
  inp=input("請輸入您想訪問頁面的url: ").strip()
  modules, func=inp.split("/")
  obj=__import__("lib."+modules, fromlist=True)modules, fromlist=True#注意字符串的拼接
  ifhasattr(obj, func):
    func=getattr(obj, func)
  else:
    print("404")
 if  __name__ = =  '__main__' :、
    run()
相關文章
相關標籤/搜索