<div class="gmail_quote">On Tue, Dec 29, 2009 at 9:33 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;">
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></blockquote><div><br>Later on I give you "the whole picture"...which you summarily toss in the garbage can. What am I supposed to do with that??<br>
 <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
> #              print 'XXX', types[x]<br>
<div class="im">>               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>
</div>What happens if you *don't* uncomment the commented line?<br></blockquote><div><br>As I mentioned, it prints BOTH the AAA and the YYY lines! The AAA is printed with something like this:<br>AAASet([purple:223344])<br>
<br></div><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"><br>
> [Tue Dec 29 00:58:10 2009] [error] [client 208.84.198.58]   File<br>
> "/var/www/html/<a href="http://angrynates.com/cart/enterProducts2.py" target="_blank">angrynates.com/cart/enterProducts2.py</a><br>
</div>> <<a href="http://angrynates.com/cart/enterProducts2.py" target="_blank">http://angrynates.com/cart/enterProducts2.py</a>>", line 138, referer:<br>
<div class="im">> <a href="http://angrynates.com/cart/enterProducts.py" target="_blank">http://angrynates.com/cart/enterProducts.py</a><br>
> [Tue Dec 29 00:58:10 2009] [error] [client 208.84.198.58]     elif<br>
> types[x][0:3] == 'set':, referer:<br>
> <a href="http://angrynates.com/cart/enterProducts.py" target="_blank">http://angrynates.com/cart/enterProducts.py</a><br>
> [Tue Dec 29 00:58:10 2009] [error] [client 208.84.198.58]        ^,<br>
> referer: <a href="http://angrynates.com/cart/enterProducts.py" target="_blank">http://angrynates.com/cart/enterProducts.py</a><br>
> [Tue Dec 29 00:58:10 2009] [error] [client 208.84.198.58] SyntaxError:<br>
> invalid syntax, referer: <a href="http://angrynates.com/cart/enterProducts.py" target="_blank">http://angrynates.com/cart/enterProducts.py</a><br>
> [Tue Dec 29 00:58:10 2009] [error] [client 208.84.198.58] Premature end<br>
> of script headers: enterProducts2.py, referer:<br>
> <a href="http://angrynates.com/cart/enterProducts.py" target="_blank">http://angrynates.com/cart/enterProducts.py</a><br>
><br>
</div>I am presuming that this is copied from an Apache error log, though you<br>
don't bother to say so.<br></blockquote><div><br>No. I just copied and pasted stuff from a previous post. I did that because I've noticed when someone posts something irrelevant, the substance of my posts sometimes gets buried. I should have edited this garbage out. <br>
</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
The issue here is that you can't just stick print statements in anywhere<br>
you like. Consider the following Python:<br>
<br>
if a == 3:<br>
    print "A is 3"<br>
print "Debugging"<br>
elif a == 4:<br>
    print "A is 4"<br>
else:<br>
    print "A is neither 3 nor 4"<br>
<br>
If you comment out the 'print "Debugging"' line you have a perfectly<br>
acceptable program. If you don't then you have something that is close<br>
to Python, but not close enough for the interpreter to be able to<br>
compile it.<br></blockquote><div><br>Duh. I might not be too sharp, but give me a little more credit than that, Steve. Come on. <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<br>
What's happening with your (CGI?) program is that the syntax error you<br>
have induced by inserting a random print statement causes an error<br>
message to be produced instead of your program's output; this doesn't<br>
look like HTTP headers. So the web server complains that your program<br>
has produced output that shouldn't be sent to any self-respecting browser.<br></blockquote><div><br>Perhaps. <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<br>
I further presume (though again I don't believe you bother to report it<br>
anywhere) that you see an "Error 500" or similar message in your web<br>
browser when you try and access the web page.<br></blockquote><div><br>Yes. I believe that's it. <br></div><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"><br>
> 2) AAA prints out before the following fields:<br>
> AAASet(['Extra-small'])<br>
> AAASet(['purple:50404D'])<br></div></blockquote><div><br>And the above is the answer to your previous question. This makes me think you really rushed through this. You are a very helpful person, but please either take the time necessary or don't answer. That is, respond only when you have the time to devote to giving a good and thoughtful answer. It's evident you didn't do that here...and you're blaming me for it. Wrong!<br>
 <br></div><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">
><br>
> 3) YYY *also* prints out twice!!<br>
><br>
> Here's the complete code once again:<br>
><br>
</div>[complete code snipped]<br>
><br>
> TIA,<br>
> beno<br>
><br>
Sorry, I don't intend to read all that code when the error you are<br>
reporting is in fact a clear demonstration that you need to further<br>
understand the principles of both Python and the web before you continue<br>
on your journey.<br></blockquote><div><br>Again, I know I'm really slow when it comes to this material. But I didn't start hacking (and it is hacking) Python code yesterday. I'm almost ashamed to admit it, but I've been at it 10 years. Again, I might be slow, but I don't think that gives you the right to tell me to go back to kindergarten. Help me out here. Or maybe somebody else will. <br>
<br>Let me restate the problem:<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. <br><br>Here's the full code again: <br></div><br></div>#! /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>                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>