Python – How to use MySQLdb when MySQL Isn’t Installed Locally

November 21st, 2011  / Author: Greg Pinero (Primary Searcher)

It turns out there’s a new MySQL connection library called MySQL Connector.

I installed it and then I just imported that into my script and everything else seemed to work normally. At least for my simply import script.

import mysql.connector as MySQLdb

I believe this library is designed for those who want to connect to MySQL on another server. It doesn’t seem to require any MySQL libraries to be installed.

When I tried to install mySQLdb it complained with the following message. I’m guessing the problem was that it requires MySQL to be installed:

File "/Users/pinerog/Downloads/MySQL-python-1.2.3/setup_posix.py", line 24, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found

Mini Searches with Answers

November 4th, 2011  / Author: Greg Pinero (Primary Searcher)

These are links associated with recent searches I’ve done. They’re not difficult enough to warrant to their own posts but still super useful.

Sun Grid Engine (SGE) – qstat – What do the states stand for?
Category State SGE Letter Code
Pending pending qw
pending, user hold qw
pending, system hold hqw
pending, user and system hold hqw
pending, user hold, re-queue hRwq
pending, system hold, re-queue hRwq
pending, user and system hold, re-queue hRwq
Running running r
transferring t
running, re-submit Rr
transferring, re-submit Rt
Suspended job suspended s, ts
queue suspended S, tS
queue suspended by alarm T, tT
all suspended with re-submit Rs, Rts, RS, RtS, RT, RtT
Error all pending states with error Eqw, Ehqw, EhRqw
Deleted all running and suspended states with deletion dr, dt, dRr, dRt, ds, dS, dT, dRs, dRS, dRT

FileMaker Pro Barcode Tutorial 2D Barcodes
I think you can use a Google chart API instead of buying this service?

git ready » pick out individual commits
A good explanation of git cherry picking.

Python Thread Pool « Python recipes « ActiveState Code
This thread pool implementation seems to work well

Should ‘Hi’, ‘thanks,’ taglines, and salutations be removed from posts? – Meta Stack Overflow
Stackoverflow just removed my greeting “hi guys”! I found the explanation here.

If you want your greeting to show up on a question prefix it with non space characters e.g.,

– hi guys,

Tags: , , , , , , , ,

Mini Searches with Answers

October 22nd, 2011  / Author: Greg Pinero (Primary Searcher)

These are links associated with recent searches I’ve done. They’re not difficult enough to warrant to their own posts but still super useful.

svn – Revision 4862: /xlwt/trunk/xlwt/examples
Useful examples of how to use the Python Excel library, xlwt.

The equivalent of Python’s repr in perl
use Data::Dumper;
$boo = ” test n”;
print Dumper($boo);

Preserving styles using python’s xlrd,xlwt, and xlutils.copy – Stack Overflow
Python Excel (xlrd, xlwt) – How to copy a style from one cell and put it on another:

newCell.xf_idx = previousCell.xf_idx

New JDBC Drivers for FileMaker 11
I was getting these errors trying to connect to FileMaker 11 via JDBC on DBVisualizer. It turns out you need this new JDBC driver.

Product: DbVisualizer Personal 7.1.5
Build: #1590 (2011/02/24 17:23)
Java VM: Java HotSpot(TM) 64-Bit Server VM
Java Version: 1.6.0_26
Java Vendor: Apple Inc.
OS Name: Mac OS X
OS Arch: x86_64
OS Version: 10.6.8

An error occurred while establishing the connection:

Long Message:
[DataDirect][SequeLink JDBC Driver]Internal network error, session aborted due to session protocol data unit format error, connection closed.

Details:
   Type: java.sql.SQLException
   Error Code: 2207
   SQL State: HY000

1) Nested Exception:

Long Message:
Session aborted due to IIOP problems.

Details:
   Type: java.sql.SQLException
   Error Code: 7772
   SQL State: HY000

2) Nested Exception:

Long Message:
IIOP error, invalid protocol identifier.

Details:
   Type: java.sql.SQLException
   Error Code: 7529
   SQL State: HY000

Mean and Standard Deviation in Python
8.3 meanstdv()

Summary
Mean and standard deviation of data

Usage
real, real = meanstdv(list)

“”" Calculate mean and standard deviation of data x[]: mean = {sum_i x_i over n} std = sqrt(sum_i (x_i – mean)^2 over n-1) “”" def meanstdv(x): from math import sqrt n, mean, std = len(x), 0, 0 for a in x: mean = mean + a mean = mean / float(n) for a in x: std = std + (a – mean)**2 std = sqrt(std / float(n-1)) return mean, std

File Requires “Full Access” to login. – FileMaker Forums – FileMaker Pro Help and Support Worldwide Community
How to fix FileMaker error:
“your access privileges do not allow you to perform this action” when logging in with a non-full-access account.

You simply want to add the extended privilege “Access via FileMaker Network (fmapp)” to make this work

Tags: , , , , , , ,

Python zipfile – Fixing Error: Unable to unarchive “..” into “Downloads”

October 19th, 2011  / Author: Greg Pinero (Primary Searcher)

I made a zip file in Python and tried to open it on my mac. I got the error mentioned in the title.

Investigating further, I got this information from running:

lm1:Downloads pinerog$ unzip -t costume_spreadsheets_from_jackrabbit.zip

Archive:  costume_spreadsheets_from_jackrabbit.zip
  End-of-central-directory signature not found.  Either this file is not
  a zipfile, or it constitutes one disk of a multi-part archive.  In the
  latter case the central directory and zipfile comment will be found on
  the last disk(s) of this archive.
unzip:  cannot find zipfile directory in one of costume_spreadsheets_from_jackrabbit.zip or
        costume_spreadsheets_from_jackrabbit.zip.zip, and cannot find costume_spreadsheets_from_jackrabbit.zip.ZIP, period.

Well, silly me, I forgot to close the zip file I made in Python. Here is the correct code for generating a zip file. Make sure you close the zip file object!

import zipfile
import glob, os

file = zipfile.ZipFile("test.zip", "w")
for name in glob.glob("samples/*"):
    file.write(name, os.path.basename(name), zipfile.ZIP_DEFLATED)
file.close()

Python – Excel – How to merge cells with xlwt

October 13th, 2011  / Author: Greg Pinero (Primary Searcher)

The sheet object has this method:

write_merge(r1,r2,c1,c2,label,style)

Style and label are optional.

There is an example of its use here:

https://secure.simplistix.co.uk/svn/xlwt/trunk/xlwt/examples/merged0.py