Custom Classes?

Victor Subervi victorsubervi at gmail.com
Wed Apr 30 12:02:10 EDT 2008


 Hi;
I have the following code which produces a file every time I need to display
an image from MySQL. What garbage! Surely, python is capable of better than
this, but the last time I asked for help on it, I got no responses. Is this
only possible with custom classes? Please, give me some guidance here!

try:

  w += 1

  getpic = "getpic" + str(w) + ".py"

  try:

    os.remove(getpic)

  except:

    pass

  code = """

#!/usr/local/bin/python

import cgitb; cgitb.enable()

import MySQLdb

import cgi

import sys,os

sys.path.append(os.getcwd())

from login import login

user, passwd, db, host = login()

form = cgi.FieldStorage()

picid = int(form["id"].value)

x = int(form["x"].value)

pics =
{1:'pic1',2:'pic1_thumb',3:'pic2',4:'pic2_thumb',5:'pic3',6:'pic3_thumb',7:'pic4',8:'pic4_thumb',\

9:'pic5',10:'pic5_thumb',11:'pic6',12:'pic6_thumb'}

pic = pics[x]

print 'Content-Type: text/html'

db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db)

cursor= db.cursor()

sql = "select " + pic + " from products where id='" + str(picid) + "';"

cursor.execute(sql)

content = cursor.fetchall()[0][0].tostring()

cursor.close()

print 'Content-Type: image/jpeg'

print

print content

"""

  script = open(getpic, "w")

  script.write(code)

  print '<td><input type="hidden" name="%s"' % str(x), ' value="%s">' % pic

  print '<img src="%s?id=%d&x=%d"><br /><br /></td>\n' % (getpic, d, y)

TIA,

Victor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080430/abcb0948/attachment.html>


More information about the Python-list mailing list