<div class="gmail_quote">On Tue, Dec 29, 2009 at 10:16 AM, Steve Holden <span dir="ltr"><<a href="mailto:steve@holdenweb.com">steve@holdenweb.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">Victor Subervi wrote:<br>
> On Tue, Dec 29, 2009 at 9:33 AM, Steve Holden <<a href="mailto:steve@holdenweb.com">steve@holdenweb.com</a><br>
</div><div class="im">> <mailto:<a href="mailto:steve@holdenweb.com">steve@holdenweb.com</a>>> wrote:<br>
><br>
>     That's a bit like being told you have to produce something green, and<br>
>     then when you do, being told "no, not that green, a light green". So you<br>
>     produce something a lighter gree and then being told "no, a slightly<br>
>     redder green". And so on.<br>
><br>
>     In other words, you aren't giving us the whole picture here, and without<br>
>     the whole picture you will only ever get bits of the answer.<br>
><br>
><br>
> Later on I give you "the whole picture"...which you summarily toss in<br>
> the garbage can. What am I supposed to do with that??<br>
><br>
</div>That isn't "the whole picture", that's "the Python soup I produced to<br>
query the SQL soup I produced because I thought it might answer my problem".<br>
<div class="im"><br>
><br>
><br>
>     > #              print 'XXX', types[x]<br>
>     >               elif types[x][0:3] == 'set':<br>
>     >                 for f in field:<br>
>     >                   print '<td>AAA%s</td>\n' % (field)<br>
>     >                 else:<br>
>     >                   print 'YYY'<br>
>     ><br>
>     > 1) If I uncomment the commented line, it throws this error:<br>
>     ><br>
>     What happens if you *don't* uncomment the commented line?<br>
><br>
><br>
> As I mentioned, it prints BOTH the AAA and the YYY lines! The AAA is<br>
> printed with something like this:<br>
> AAASet([purple:223344])<br>
><br>
</div>Try moving the "else" so it's associated with the "if ... elif" rather<br>
than the "for". It's currently indented one level too far.<br></blockquote><div><br>There is currently an else where you indicate, as one can see in the complete code I am once again supplying with this post. That prints out pretty much all the other fields and does so just fine.<br>
<br>Once again, it seems nobody is bothering to address this issue. Is it beyond your reach as it is beyond mine? I feel compelled to restate the problem once again as I did in my original post, and to once again post the entire code. Hopefully someone will help me see my error.<br>
<br>I'm using python 2.4.3 which apparently requires that I import Set:<br>from sets import Set<br>I've
done this. In another script I successfully manipulated MySQL sets by
so doing. Here's the code snippet from the script where I was able to
call the elements in a for loop:<br>
<br>          if isinstance(colValue[0], (str, int, float, long, complex, unicode, list, buffer, xrange, tuple)):<br>            pass<br>          else:<br>            try:<br>              html = "<b>%s</b>: <select name='%s'>" % (col, col)<br>

              notSet = 0<br>              for itm in colValue[0]:<br>                try:<br>                  color, number = itm.split(':')<br>                  html += "<option name='%s'>%s</option>" % (itm, color)<br>

                except:<br>                  html += "<option name='%s'>%s</option>" % (itm, itm)<br> <br>However,
when I try that in my current script, the script fails. It throws no
error, but rather just quits printing to the screen. Here's the code
snippet:<br>
<br>              elif types[x][0:3] == 'set':<br>                for f in field:<br>                  print '<td>%s</td>\n' % (field)<br>              else:<br>                print '<td>%s</td>\n' % (field)<br>

<br>Notice that I can slice to determine if it's a set (I've printed
something after that call to be sure). But once I try to loop through
the set it quits printing to screen. The entire code follows. <br><br>#! /usr/bin/python<br><br>import MySQLdb<br>import cgi<br>import sys,os<br>sys.path.append(os.getcwd())<br>from login import login<br>from sets import Set<br>
<br>def enterProducts2():<br>  print '''Content-type: text/html<br><br><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><br><html><br><head><br><title></title><br>
</head><br><body><br><form enctype='multipart/form-data' action='enterProducts3.py' method='post'><br>'''<br>  form = cgi.FieldStorage()<br>  store = form.getfirst('store')<br>
  print "<input type='hidden' name='store' value='%s' />" % store<br>  user, passwd, db, host = login()<br>  count = 0<br>  count2 = 0<br>  db = MySQLdb.connect(host, user, passwd, db)<br>
  cursor = db.cursor()<br>  cursor.execute('select ID from %s;' % store)<br>  test = cursor.fetchall()<br>  if len(test) > 0:<br>    cursor.execute('show columns from %s;' % store)<br>    colNames = [itm[0] for itm in cursor]<br>
    types = [itm[1] for itm in cursor]<br>    colNamesWithCommas = ', '.join(colNames)<br>    try:<br>      cursor.execute('select ID from %s;' % store)<br>      ids = cursor.fetchall()<br>      if store == 'prescriptions':<br>
        cursor.execute('show tables like "%PersonalData";')<br>        personalDataTables = [itm[0] for itm in cursor]<br>      else:<br>        personalDataTables = []<br>      print '<h1>%s</h1>\n<table><tr><td>\n' % (store[0].upper() + store[1:])<br>
      print '<h3>What do you want to do?</h3>\n<table><tr><td>\n'<br>      print "<input type=radio name='whatDo' value='insert' />Add<br />\n"<br>
      print "<input type=radio name='whatDo' value='update' />Update<br />\n"<br>      print "<input type=radio name='whatDo' value='delete' />Delete<br />\n"<br>
      print '</td></tr></table>\n<br /><br />\n'<br>      print '<table border=1>\n'<br>      print '<tr>\n'<br>      print '<th align=center><b>Check</b></th>\n'<br>
      i = 0<br>      while i < len(colNames):<br>        if i == 0: # This is the ID field<br>          print '<th align=center><b>', colNames[i], '</b></th>\n'<br>          try:<br>
            cursor.execute('describe relationships%s;' % (store[0].upper() + store[1:]))<br>            relationshipsDescription = cursor.fetchall()<br>            cursor.execute('select * from relationships%s where %sID="%s";' % (store[0].upper() + store[1:], store[0].upper() + store[1:], ids[0][0]))<br>
            relationshipFields = cursor.fetchone()<br>            j = 0<br>            for relDescrip in relationshipsDescription:<br>              if j != 0: # Skip the store ID<br>                print '<th><b>%s Name</b></th>\n' % (relDescrip[0][:-2])<br>
              j += 1<br>          except:<br>            pass # There are no relationships<br>        else:<br>          print '<th align=center><b>', colNames[i], '</b></th>\n'<br>
        i += 1<br>      print '</tr>\n'<br>      j = 0<br>      z = 3<br>      a = 0<br>      for id in ids:<br>        a += 1<br>        j += 1<br>        for d in id:<br>          bg = ['#ffffff', '#d2d2d2', '#F6E5DF', '#EAF8D5']<br>
          z += 1<br>          print '<tr bgcolor="%s">' % bg[z % 4]<br>          cursor.execute('select * from %s where ID=%s;' % (store, str(d)))<br>          col_fields = cursor.fetchall()<br>
          col_fields = col_fields[0]<br>          tmp = []<br>          for field in col_fields:<br>            tmp.append(field)<br>          col_fields = []<br>          for field in tmp:<br>            col_fields.append(field)<br>
          i = 0<br>          x = 0<br>          y = 0<br>          w = 0<br>          for field in col_fields:<br>            if colNames[x] == 'SKU':<br>              sku = field<br>            if colNames[x][:3] == 'pic':<br>
              y += 1<br>              w += 1<br>              print '<td><input type="hidden" name="%s" />\n' % str(x)<br>#                im = Image.open(getpic)<br>#                width, height = im.size()<br>
#                for infile in sys.argv[1:]:<br>#                  outfile = os.path.splitext(infile)[0] + "_thumb.jpg"<br>#                  if infile != outfile:<br>#                    try:<br>#                      im = Image.open(infile)<br>
#                      im.thumbnail((128, (width/128)*height), Image.ANTIALIAS)<br>#                      im.save(outfile, "JPEG")<br>#                    except IOError:<br>#                     print "cannot create thumbnail for ", infile<br>
#                print '<img src="%s"><br /><br /></td>\n' % (outfile)<br>              print '<img src="getpic.py?store=%s&pic=%d&id=%s" width="100"></td>\n' % (store, w-1, ids[0][0])<br>
              count2 += 1<br>            else:<br>              if x == 0:<br>                # This is the ID field<br>                d = id[0]<br>                check = 'check' + str(d)<br>                i += 1<br>
                print '<td><input type="checkbox" name="', check, '" value="', field, '" /></td>\n'<br>                print '<td>%s</td>\n' % (field)<br>
                if personalDataTables != []:<br>                  i = 0<br>                  for relField in relationshipFields:<br>                    if i != 0: # The first value is the same as d<br>                      sql = 'select FirstName, LastName from %sPersonalData where ID="%s";' % (relationshipsDescription[i][0][:-2].lower(), relField)<br>
                      cursor.execute(sql)<br>                      names = cursor.fetchone()<br>                      print '<td>%s %s</td>\n' % (names[0], names[1])<br>                    i += 1<br>              elif types[x][0:3] == 'set':<br>
                for f in field:<br>                  print '<td>%s</td>\n' % (field)<br>                else:<br>                  print 'YYY'<br>              else:<br>                if (isinstance(field, str)) and (len(field) > 60):<br>
                  print '<td>%s</td>\n' % (field[:60] + '...')<br>                else:<br>                  print '<td>%s</td>\n' % (field)<br>            x += 1<br>      print '</tr><tr>\n'<br>
      print '<td align=center colspan=', len(colNames) + 1, '>\n'<br>      print '</td></tr></table>\n'<br>      print '<input type="hidden" name="count" value="%s" />\n' % count2<br>
      print '<input type="submit" value=" Send " />\n'<br>    except:<br>      print 'There is no data yet. Please add a product.\n<br /><br />'<br>      print "<input type='hidden' name='whatDo' value='insert' />\n"<br>
      print '<input type="submit" value=" Add " />\n'<br>  else:<br>    print 'There is no data yet. Please add a product.\n<br /><br />'<br>    print "<input type='hidden' name='whatDo' value='insert' />\n"<br>
    print '<input type="submit" value=" Add " />\n'<br>  print '''<br></form><br></body><br></html><br>'''<br>  cursor.close()<br><br>enterProducts2()<br>
<br>TIA,<br>beno<br></div></div>