sqlobject vs mysqldb module

Y

yaffa

dear group,

i have a python script that scrapes contents from an html file and i
would like to have the script write values to a mysql db. do you
recommend i go with the sqlobject or the mysqldb module?

thank you

yaffa
 
S

skip

yaffa> i have a python script that scrapes contents from an html file
yaffa> and i would like to have the script write values to a mysql db.
yaffa> do you recommend i go with the sqlobject or the mysqldb module?

They are really quite different beasts. You'll have to consider your
requirements to decide which to use.
 
J

Jeffrey E. Forcier

Skip is correct, they're somewhat different:

SQLObject is an 'ORM' or 'Object-Relational Mapping', meaning that it
allows you to handle everything related to the database with objects.
The table handles are objects, the result set is an object, the
individual rows in a result set are objects with attributes for the
fields/columns. So instead of "SELECT id,name FROM people WHERE
location='New York'", you'd do something like the following:

for row in People.selectBy(location='New York'):
print "id: %s, name: %s" % (row.id,row.name)

This is nice if you value object-oriented code very highly, and don't
have any specific SQL-level tricks you wish to employ (although
SQLObject can handle those as well, I'm told, it's just not its main
function).

MySQLDB, while I haven't used it specifically, is probably similar to
its Postgres cousins pyPgSQL and psycopg, in that it just provides a
Python DB API compliant interface to the database (see
http://www.python.org/peps/pep-0249.html).

Such modules do not provide much or any object orientation, sticking
with a more low-level approach of making SQL calls and getting
dictionaries back, to wit:

conn = [module_name].connect(connection_args)
cursor = conn.cursor()
cursor.execute("SELECT id,name FROM people WHERE location='New York'")
print cursor.fetchall()


Anyway, sorry if that's over your head (it's hard to tell your
experience level from your post), but the basic gist is that SQLObject
is good for a higher-level and very easy-to-use database connection,
and MySQLDB is probably good if you're very comfortable with SQL and
not so much with object-oriented programming (or if you have any other
reason to prefer straight SQL queries).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top