[Tutor] Problems when displaying numbers

Patricia patriciap.gu at gmail.com
Wed Apr 12 22:56:12 CEST 2006


Hi,

This is my code:

conn =  MySQLdb.connect(host = "localhost", user = "root", passwd = "",
                        db ="mydb")
cursor = conn.cursor()
cursor.execute("""SELECT h, k, l, m, s, t
FROM targets WHERE target_name = %s""", (target))
result = cursor.fetchone()

alist = helperfunc.calc_numbers(list(result)) # read below

cursor.close()
conn.close()
        
for li in alist:
    if li == '':
         s = s + "<td ALIGN='center'></td>" 
     else:
         s = s + "<td ALIGN='center'>%s</td>" % li   # problem here


calc_numbers is a method in helperfunc.py that takes the list of values
that I retrieved from the database and then does some calculations 
(addition & division) and also replaces a specific number with ''.
 
When I display the results, most of the times everything looks right, BUT
sometimes I get i.e.  15%% instead of 15. I don't understand why %% is 
added to some of the numbers being displayed. I've noticed that the numbers 
that show %% are the ones that have been modified in the calc_numbers 
method. The numbers that are not touched in that method, don't show it. 
When I printed the list obatined from the calc_numbers method, the 
numbers that have not been touched have an L at the end (i'm assuming 
it stands for long). As I said these numbers are displayed correctly 
all the time. I'm really hoping someone can point me to the right direction
because I've tried different things and nothing seems to work.

Another quick question, my page shows several drop down boxes with 
pre-selected values. When I submit the form or open the page, the 
preselected values appear, but when I press the reload button, 
they don't. (Mozilla)

Thanks,
Patricia







More information about the Tutor mailing list