473,249 Members | 1,878 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,249 software developers and data experts.

Tuples !?!?

Hi,

Is the tuple comparison brooked in python ?!?!?

Thanks.

Try this and you will see funny things:

# -*- coding: cp1252 -*-
import random
import csv
import struct
import array

def gera_string(res):

# acampo3
acampo3=((0,5,'muito reduzidos'),(6,20,'reduzidos'),
(21,32,'satisfatórios'),(33,40,'bons'),(41,45,'exc elentes'))
# acampo4
acampo4=((0,2,'reduzidos'),(3,4,'medianos'),(5,5,' elevadas'))
# acampo5
acampo5=((0,2,'reduzidos'),(3,4,'médias'),(5,5,'el evados'))
# acampo6
acampo6=((0,2,'fracos'),(3,4,'satisfatórios'),(5,5 ,'elevados'))
# acampo7
acampo7=((0,2,'pouco'),(3,4,'bastante'),(5,5,'quas e sempre'))
# acampo8
acampo8=((0,4,'mal'),(5,9,'satisfatoriamente'),(10 ,10,'de forma
exemplar'))
# acampo9
acampo9=((0,2,'muito reduzidos'),(3,4,'reduzidos'),
(5,8,'satisfatórios'),(9,10,'elevados'))
# acampo10
acampo10=((0,2,'pouco'),(3,4,'bastante'),(5,5,'mui to'))
# acampo11
acampo11=((0,2,'muito pouco'),(3,4,'pouco'),(5,8,'bastante'),
(9,10,'grande'))

campo1=res[0]
campo2=res[1]
campo3=res[2]
campo4=res[3]
campo5=res[4]
campo6=res[5]
campo7=res[6]
campo8=res[7]
campo9=res[8]
campo10=res[9]
campo11=res[10]

for a in acampo3:
x=a[0]
y=res[2]
z=a[1]
print x
print y
print z
print x < y
print y < z
print z < y
if a[0] <= res[2] <= a[1]:
campo3=a[2]

for a in acampo4:
if (res[3]>=a[0] and res[3]<=a[1]):
campo4=a[2]

for a in acampo5:
if (res[4]>=a[0] and res[4]<=a[1]):
campo5=a[2]

for a in acampo6:
if (res[5]>=a[0] and res[5]<=a[1]):
campo6=a[2]

for a in acampo7:
if (res[6]>=a[0] and res[6]<=a[1]):
campo7=a[2]

for a in acampo8:
if (res[7]>=a[0] and res[7]<=a[1]):
campo8=a[2]

for a in acampo9:
if (res[8]>=a[0] and res[8]<=a[1]):
campo9=a[2]

for a in acampo10:
if (res[9]>=a[0] and res[9]<=a[1]):
campo10=a[2]

for a in acampo11:
if (res[10]>=a[0] and res[10]<=a[1]):
campo11=a[10]

...

return frase

# processar

f=open('leituras.csv','rb')
csv.register_dialect('dialecto', delimiter=';',
quoting=csv.QUOTE_NONE)
leitor =csv.reader(f,'dialecto')

for res in leitor:
print res
print gera_string(res)

f.close()

quit()

Dec 11 '07 #1
11 1246
On 2007-12-11, aa*****@gmail.com <aa*****@gmail.comwrote:
Hi,

Is the tuple comparison brooked in python ?!?!?
No.
Thanks.
You're welcome.
Try this and you will see funny things:
No thanks.

Maybe you could to post a smaller, easier to read example of
what you think is broken?

--
Grant Edwards grante Yow! I demand IMPUNITY!
at
visi.com
Dec 11 '07 #2
aa*****@gmail.com a écrit :
Hi,

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.
Dec 11 '07 #3
Is the tuple comparison brooked in python ?!?!?
>
No.
Thanks.

You're welcome.

HHH! That just made my day. Too funny.

2B
Dec 11 '07 #4
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,'exc elentes'))
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...@free.quelquepart.frwrote:
aara...@gmail.com a écrit :
Hi,
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.
Dec 11 '07 #5
On 11 Dez, 22:02, aara...@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,'exc elentes'))
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...@free.quelquepart.frwrote:
aara...@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.
Dec 11 '07 #6
On 12/11/2007 5:08 PM, aa*****@gmail.com wrote:
On 11 Dez, 22:02, aara...@gmail.com wrote:
>Ok. This is small code.

The problem is '2' != 2 there is a way of converting 'some number' in
number ?

<snip>

>>ord('2')
50
>>chr(50) == '2'
True
>>int('2')
2
>>int('2') == 2
True
>>>
Dec 11 '07 #7
aa*****@gmail.com a écrit :
Ok. This is small code.

The problem is '2' != 2
It would indeed be a problem if this expression eval'd to True. That's
the case in some, hem, 'languages', and believe me it's *not* the
RightThing.
there is a way of converting 'some number' in
number ?
assert(2 == int(2))

Anything else about tuples ?-)
Dec 12 '07 #8
Bruno Desthuilliers wrote:
aa*****@gmail.com a écrit :
>The problem is '2' != 2

It would indeed be a problem if this expression eval'd to True.
That's the case in some, hem, 'languages', and believe me it's
*not* the RightThing.
What kind of "hem" language is this? :)
>>'2' != 2
True
>>>
Regards,
Björn

--
BOFH excuse #430:

Mouse has out-of-cheese-error

Dec 12 '07 #9
Bjoern Schliessmann a écrit :
Bruno Desthuilliers wrote:
>>aa*****@gmail.com a écrit :

>>>The problem is '2' != 2

It would indeed be a problem if this expression eval'd to True.
That's the case in some, hem, 'languages', and believe me it's
*not* the RightThing.


What kind of "hem" language is this? :)
>
>>>>'2' != 2

True
hem... Sorry, I of course meant that it would be a problem if '2' == 2
eval'd to true - or '2' != 2 eval'd to false. My bad...

Thanks for the correction anyway.

Ah, and, yes, the 'hem' language I was thinking about has a three
letters recursive acronym for name and is widely (and mostly) used for
web applications. Should I spell the name, or did you guess ?-)
Dec 12 '07 #10
Ok people. No more discussions about this. I tought the conversion
occurs automatic but it is not case. I'm a newbie on python. Thanks to
everybody. ;-)

On 12 Dez, 19:43, Bruno Desthuilliers
<bdesth.quelquech...@free.quelquepart.frwrote:
Bjoern Schliessmann a écrit :
Bruno Desthuilliers wrote:
>aara...@gmail.com a écrit :
>>The problem is '2' != 2
>It would indeed be a problem if this expression eval'd to True.
That's the case in some, hem, 'languages', and believe me it's
*not* the RightThing.
What kind of "hem" language is this? :)
>>>'2' != 2
True

hem... Sorry, I of course meant that it would be a problem if '2' == 2
eval'd to true - or '2' != 2 eval'd to false. My bad...

Thanks for the correction anyway.

Ah, and, yes, the 'hem' language I was thinking about has a three
letters recursive acronym for name and is widely (and mostly) used for
web applications. Should I spell the name, or did you guess ?-)
Dec 12 '07 #11
On Dec 11, 3:08 pm, aara...@gmail.com wrote:
On 11 Dez, 22:02, aara...@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,'exc elentes'))
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...@free.quelquepart.frwrote:
aara...@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
>>>
Dec 13 '07 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Ivan Voras | last post by:
Are there any performance/size differences between using tuples and using lists? -- -- Every sufficiently advanced magic is indistinguishable from technology - Arthur C Anticlarke
42
by: Jeff Wagner | last post by:
I've spent most of the day playing around with lists and tuples to get a really good grasp on what you can do with them. I am still left with a question and that is, when should you choose a list or...
3
by: Thorsten Kampe | last post by:
I found out that I am rarely using tuples and almost always lists because of the more flexible usability of lists (methods, etc.) To my knowledge, the only fundamental difference between tuples...
66
by: Darren Dale | last post by:
Hello, def test(data): i = ? This is the line I have trouble with if i==1: return data else: return data a,b,c,d = test()
11
by: Noah | last post by:
I have a list of tuples I want to reverse the order of the elements inside the tuples. I know I could do this long-form: q = y = for i in y: t=list(t)
5
by: fff_afafaf | last post by:
Do you know is it possible to put different kinds of tuples to one container? E.g. to a vector? (The lengths of the tuples are different, and also the types in the tuples are different.. -Is it...
10
by: rshepard | last post by:
While working with lists of tuples is probably very common, none of my five Python books or a Google search tell me how to refer to specific items in each tuple. I find references to sorting a list...
12
by: rshepard | last post by:
I'm a bit embarrassed to have to ask for help on this, but I'm not finding the solution in the docs I have here. Data are assembled for writing to a database table. A representative tuple looks...
122
by: C.L. | last post by:
I was looking for a function or method that would return the index to the first matching element in a list. Coming from a C++ STL background, I thought it might be called "find". My first stop was...
27
by: seberino | last post by:
Please help me think of an example where immutable tuples are essential. It seems that everywhere a tuple is used one could just as easily use a list instead. chris
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.