Python: class method returns empty list

0

I am trying to practice a bit of Python in my free time, and for that I apply the problems of the university to the reasoning in this language. I am trying to calculate contours and everything is fine until I try values to the running method, for this I used a list and iterated over the possible curves adding the desired values to the end of the list.

The problem is that when I declare the object in code everything works fine, but when I declare it by obtaining it from a dictionary of a previous import it returns the empty list.

'from numpy import linspace as lp
from math import fmod
import os
import importarchi

class Punto(object):
    def __init__(self, descripcion, ordenada, absisa, elevacion, *args):
         self.descripcion = descripcion
         self.ordenada = ordenada
         self.absisa = absisa
         self.elevacion = elevacion
         self.args = args

def __repr__ (self):
    return 'El punto ellegido es {!r} con una elevacion de {!r} m'.format(self.descripcion, self.elevacion)

def cerc_puntos(self, otro):
    x = self.absisa - otro.absisa
    y = self.ordenada - otro.ordenada
    if abs(x - y) != 10:
        return False
    else:
        return True

def delta(self, otro):
    x = self.elevacion - otro.elevacion
    if x > 0 :
        return 'Bajando'
    elif x < 0:
        return 'Subiendo'
    elif x == 0: 
        return 'Terreno plano'

def cant_curvas(self, otro):
    curvas = []
    if self.delta(otro) == 'Bajando':
        x = self.elevacion
        while x >= otro.elevacion:
            if fmod(x, 0.25) > 0.249 or fmod(x, 0.25) == 00:
                dst = self.elevacion - x
                dist_papel = (dst * 10) / abs(self.elevacion - otro.elevacion) 
                tot = (round(x, 2), round(dst,2), round(dist_papel,2))
                curvas.append(tot)
            x -= 0.01
        return curvas

    elif self.delta(otro) == 'Subiendo':
        x = self.elevacion
        while x <= otro.elevacion:
            if fmod(x, 0.25) < 0.001 or fmod(x, 0.25) == 00:
                dst = x - self.elevacion
                dist_papel = (dst * 10) / abs(self.elevacion - otro.elevacion) 
                tot = (round(x, 2), round(dst,2), round(dist_papel,2))
                curvas.append(tot)
            x += 0.01
        return curvas'

I'm trying to call an example print a.cant_curvas(b) but it returns the empty list, on the other hand if I declare it% a = Punto('A',100,0,101.25) b = Punto('B', 100,0,99.33) print a.cant_curvas(b) I get [(101.25, 0.0, 0.0), (101.0, 0.25, 1.3), (100.75, 0.5, 2.6), (100.5, 0.75, 3.91), (100.25, 1.0, 5.21), (100.0, 1.25, 6.51), (99.75, 1.5, 7.81), (99.5, 1.75, 9.11)]

This would be the assignment of values.

while True:
try:
    pp1 = raw_input('introduce 1er punto: ').upper()
    if pp1 == 'Q':
        exit()
    else:
        primpunt = (pp1, importarchi.dicciolect[pp1])
        print primpunt[0], primpunt[1][0], primpunt[1][1], primpunt[1][2]
        ppunt=Punto(primpunt[0], primpunt[1][0], primpunt[1][1], primpunt[1][2])
        print ppunt
        break

except KeyError:
    print 'el valor debe ser un punto valido'

while True:
    try:
        pp2 = raw_input('introduce punto 2do: ').upper()
        if pp2 == 'Q':
            exit()
        else:
            segpunt = (pp2, importarchi.dicciolect[pp2])
            spunt = Punto(segpunt[0], segpunt[1][0], segpunt[1][1],segpunt[1][2] )
            print spunt
            break
    except KeyError:
        print 'el valor debe ser un punto valido'
print ppunt.cant_curvas(spunt)

thanks.

    
asked by max 23.01.2018 в 05:05
source

0 answers