1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| #Creation de la classe Sample
class SampleClass :
def __init__(self, HoleId, SampleId, Depth, THM):
self.HoleId=HoleId
self.SampleId=SampleId
self.Depth=Depth
self.THM=THM
#methode permettant de retourner une representation
#en string de l'objet
def __str__(self):
out = "Hole %d Sample %d Depth %f THM %d" \
%(self.HoleId, self.SampleId, self.Depth, self.THM)
return out
#methode de comparaison general basee sur
#l'attribut Depth
def __cmp__(self,sample2):
return cmp(self.Depth, sample2.Depth)
#Liste globale des samples
SampleList = []
#Fonction qui va permettre d'afficher le contenu de ma liste
def affichSamples():
print"Liste des Samples:\n"
for samp in SampleList:
print"\t",samp
s1 = SampleClass(10,101,1.5,3)
s2 = SampleClass(10,102,3,3)
s3 = SampleClass(10,103,4.5,3)
s4 = SampleClass(10,104, 6, 3)
SampleList=[s4,s1,s3,s2]
affichSamples()
SampleList.sort()
affichSamples() |
Partager