Python
This is a page dedicated to me learning python.
No module named ez_setup
While trying to install a package, you get:
Traceback (most recent call last):
File "setup.py", line 12, in <module>
from ez_setup import use_setuptools
ImportError: No module named ez_setup
On CentOS (or other RHEL derivatives), run:
yum install python-setuptools
On other platforms, it's probably named {{code|python-distutils
MySQL
To install the MySQL connector:
yum instal MySQL-python
To use it, import {{code|_mysql, or you can use the {{code|MySQLdb wrapper. Basically, to fetch something, we can now do:
import MySQLdb as mdb # Wraps _mysql
import sys
con = mdb.connect("search", "lyricslive", "lyricslive", "lyricslive")
with con:
cur = con.cursor(mdb.cursors.DictCursor)
cur.execute("SELECT * FROM lyric LIMIT 1")
results = cur.fetchall()
for record in results:
print record["lyric"]
The above is analogous to {{code|<?php $result = mysql_fetch_array($handle); ?>. If we take out {{code|mdb.cursors.DictCursor, the records will not be in a dictionary but rather fields.