469,568 Members | 1,643 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,568 developers. It's quick & easy.

sqlobject vs mysqldb module

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

Aug 9 '05 #1
2 1298
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.

--
Skip Montanaro
sk**@pobox.com
Aug 9 '05 #2
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).

Aug 9 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by jacob.miles | last post: by
1 post views Thread by Oleg Broytmann | last post: by
reply views Thread by Oleg Broytmann | last post: by
reply views Thread by Oleg Broytmann | last post: by
reply views Thread by Oleg Broytmann | last post: by
2 posts views Thread by Oleg Broytmann | last post: by
reply views Thread by Guillermo Heizenreder | last post: by
4 posts views Thread by petr.jakes.tpc | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.