[Tutor] Error when calling a class

Rikard Bosnjakovic rikard.bosnjakovic at gmail.com
Sun Feb 18 16:04:22 CET 2007


On 2/18/07, kubota2550 at gmail.com <kubota2550 at gmail.com> wrote:

> import classctof
> y=classctof.fahrenheit(1)
> print y
>
> What am I doing wrong to get it to pass the answer back to the calling
> program?

You need to instancify the class first before calling its methods:


import classctof

# make an instance
y = classctof.Temperature()

# add the property. it's usually better to let the method handle this
y.celcius = 42

# convert
f = y.fahrenheit()




-- 
- Rikard.


More information about the Tutor mailing list