Tuples !?!?

Jason tenax.raccoon at gmail.com
Thu Dec 13 10:33:19 EST 2007


On Dec 11, 3:08 pm, aara... at gmail.com wrote:
> On 11 Dez, 22:02, aara... at gmail.com wrote:
>
> > Ok. This is small code.
>
> > The problem is '2' != 2 there is a way of converting 'some number' in
> > number ?
>
> > Thanks.
>
> > # -*- coding: cp1252 -*-
> > import random
> > import csv
> > import struct
> > import array
>
> > # resultados para colocar nos campos
> > def gera_string(res):
>
> >         # acampo3
> >         acampo1=((0,5,'muito reduzidos'),(6,20,'reduzidos'),
> > (21,32,'satisfatórios'),(33,40,'bons'),(41,45,'excelentes'))
> >         campo1=''
>
> >         for a in acampo1:
> >                 print res[1]
> >                 if (res[1]>=a[0] and res[1]<=a[1]):
> >                         campo1=a[2]
>
> >         return campo1
>
> > # processar
>
> > res=['a','2']
>
> > print gera_string(res)
>
> > quit()
>
> > On 11 Dez, 20:40, Bruno Desthuilliers
>
> > <bdesth.quelquech... at free.quelquepart.fr> wrote:
> > > aara... at gmail.com a écrit :
>
> > > > Hi,
>
> Thanks. I have found that there is int() function on python. The print
> function always show me a number when was 'number'. Ok thanks.
>
> > > > Is the tuple comparison brooked in python ?!?!?
>
> > > Given the size and average level of the user base, I think this would
> > > have been noticed.
>
> > > > Try this
>
> > > If you hope anyone to try anything, please post the *minimal* working
> > > code showing the problem. And while your at it, also explain the
> > > expected result.
>
> > > > and you will see funny things:
>
> > > Sorry but the only thing I see so far is that your code needs refactoring.

Python objects have two ways of representing themselves.  The print
statement converts the objects in it into strings.  Python objects can
also have a representative string which should give you enough
information to determine if you're dealing with a number or a string.
You can get this representative string via the repr() built-in
function.  To get the normal string of an object, the str() built-in
will perform the conversion.

If you're using the string formatting operator (%), the "%s" specifier
will use the normal string, while the "%r" specifier will use the
representative string.

Please note that repr() will show you *all* the digits of a floating
point number, while the normal string conversion may round.  This is
because floating-point numbers cannot represent most decimal exactly.
This isn't a flaw in Python, but a flaw in all IEEE floating-point
hardware (ie, your processor).

If you're using Python interactively, Python will display the results
of expressions with their representative strings.

For example:
>>> 5
5
>>> '5'
'5'
>>> 0.1
0.10000000000000001
>>> print '5', 5
5 5
>>> print repr('5'), repr(5)
'5' 5
>>> print 'Normal Strings: %s, %s, %s' % ('5', 5, 0.1)
Normal Strings: 5, 5, 0.1
>>> print 'Repr Strings: %r, %r, %r' % ('5', 5, 0.1)
Repr Strings: '5', 5, 0.10000000000000001
>>>



More information about the Python-list mailing list