[Tutor] calling a method within a function

John washakie at gmail.com
Tue Dec 7 23:36:37 CET 2010


Hello,

I have a strange problem with a piece of code I've written. It's a bit
overly complicated to make an example with, but the gist is below. But
in the example below, it works. However, in my example, when I call
the method from within the function, it returns something other than
what I expect. If I call the method outside the function, it behaves
properly???



class DataHolder():
    def __init__(self):
        self.x = np.arange(100)
    def f(self,wl):
        f = np.sin(self.x) ** wl
        return f


def function(DH,wl=20):
    f = DH.f(wl)
    plt.plot(DH.x,f)


More information about the Tutor mailing list