[Tutor] Problems when displaying numbers

w chun wescpy at gmail.com
Thu Apr 13 05:24:20 CEST 2006


hi patricia,

it would be really helpful to see an example of 'result' before and
after the call to calc_numbers() as well as the code for calc_numbers
if possible.

this will likely reveal the problem that you are having.

thanks,
-wesley


On 4/12/06, Patricia <patriciap.gu at gmail.com> wrote:
> 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
>
>
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>


--
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
    http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com


More information about the Tutor mailing list