python操作mysql
根据php思路写的,最近有空的时候学一点python。
# -*- coding: UTF-8 -*- import pymysql class db_mysql(object): conn = None def __init__(self, host, username, password, db, charset='utf8', port=3306): self.host = host self.username = username self.password = password self.db = db self.charset = charset self.port = port self.conn = pymysql.connect(host=self.host, port=self.port, user=self.username, password=self.password, db=self.db,charset=self.charset) self.cursor = self.conn.cursor(cursor=pymysql.cursors.DictCursor) def sql_str(self,str): #str = str.replace("'","''") str = str.replace("\\","\\\\") return str def close(self): self.cursor.close() self.conn.close() def select_one(self, sql, params=()): result = None try: #self.connect() self.cursor.execute(sql, params) result = self.cursor.fetchone() #self.close() except Exception as e: print(e) return result def select_all(self, sql, params=()): list_data = () try: #self.connect() self.cursor.execute(sql, params) list_data = self.cursor.fetchall() #self.close() except Exception as e: print(e) return list_data def dosql(self, sql, params={}): sql=self.sql_str(sql) #print(sql) count = 0 try: #self.connect() count = self.cursor.execute(sql, params) self.conn.commit() #self.close() except Exception as e: print(e) return count
说实话,这门语言不复杂,但是没有大括号,强迫症看着特别不舒服。语法上跟javascript很接近,就看了菜鸟教程上手就干。以前也用过一点,只是脚本处理点东西,没有系统的写demo。
个人感觉开发语言(各种开发语言)的学习主要以下几段
1、数据库的增删改查,基础练习。
2、post、get等前后端接口交互。(到这应该自己可以做小网站 了)
3、session、文件存储,execl导入导出、上传下载、二维码生成等等业务场景下的常见库使用。(这些一般都有比较容易找到的教程,有了这些做业务后台基本功能差不多可以了,找工作可能还不那么顺利)
4、sdk以及第三方库使用。复杂点功能往往去直接使用别人的sdk或库。发短信、语音、文字识别、支付、代扣等等,这些掌握就得慢慢积累了,文档啥的不会像常用库那么全,遇到坑一时半会不一定能爬出来。(只有这个熟练了,找工作才好找)
35岁了,补充知识吧,不知道后面工作危机了啥个情况。