Skip to content

Instantly share code, notes, and snippets.

@HaleysCommit
HaleysCommit / dbhelper.py
Created May 19, 2022 06:11 — forked from jaytaylor/dbhelper.py
Python Database Helper
import MySQLdb
##
# @author Jay Taylor [@jtaylor]
# @date 2010-11-15
#
# @description This is a basic database helper script which will setup the connection.
#
# @requirements The MySQLdb package must be installed, i.e. `sudo easy_install MySQLdb`
#
@HaleysCommit
HaleysCommit / db_helper.py
Created May 19, 2022 06:13 — forked from anjianshi/db_helper.py
python MySQLdb helper
# -*- coding: utf-8 -*-
import MySQLdb
def get_db(database, user="root", passwd=None, charset='utf8'):
return MySQLdb.connect(host="localhost", user=user, passwd=passwd, db=database, charset=charset)
def execute(db, sql):
cur = db.cursor()
@HaleysCommit
HaleysCommit / beautiful_idiomatic_python.md
Created September 5, 2024 12:30 — forked from 0x4D31/beautiful_idiomatic_python.md
[Beautiful Idiomatic Python] Transforming Code into Beautiful, Idiomatic Python #python

Transforming Code into Beautiful, Idiomatic Python

Notes from Raymond Hettinger's talk at pycon US 2013 video, slides.

The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Looping over a range of numbers

for i in [0, 1, 2, 3, 4, 5]: