Jan-19-2018, 11:21 PM
Hi !
I always thought I could pass instance variable between functions (intraclass, at least). In the following code snippet I am unable to do so.
It is the first time I've run into this problem.
This is generally fine...
Please help?
I always thought I could pass instance variable between functions (intraclass, at least). In the following code snippet I am unable to do so.

This is generally fine...
class Foo(): def __init__(self, *args): self.arg0 = arg0 self.arg1 = arg1 self.arg2 = arg2 def bar(self): self.thing0 = self.arg0 + self.arg1 print(self.thing0) return self.thing0 def moo(self): self.thing1 = self.thing0/self.arg2 print('This is : {}.'.format(self.thing1) return self.thing1When I run my code with the following I get an error telling me the class doesn't have any of the attributes I'm printing in print_generic_info(). It shouldn't matter. I've never had this happen before.
class Foo(): --SNIP-- def generic_info(self,vrate=0.05): self.vrate = vrate self.monthly_income = self.income/self.units/12 self.vmi = (1-self.vrate) * self.monthly_income if (0<=self.age<=35): self.upkeep = float(0.05 * self.monthly_income) self.vupkeep = float(0.05 * self.vmi) elif (35<self.age<=60): self.upkeep = float(0.1 * self.monthly_income) self.vupkeep = float(0.1 * self.vmi) else: self.upkeep = float(0.2 * self.monthly_income) self.vupkeep = float(0.2 * self.vmi) self.pretax_income = self.monthly_income - self.upkeep self.vpretax_income = self.vmi - self.vupkeep return self.monthly_income, self.upkeep, self.pretax_income, self.vmi, self.vupkeep, self.vpretax_income #I am returning properly but they are not passing through def print_generic_info(self): print('Your monthly income is...${}. Monthly upkeep is ${}.\nMonthly pretax is ${}.'.format(self.monthly,self.upkeep,self.pretax))in my main file:
from fooclassfile import Foo --SNIP-- print_generic_info()Idk why this is happening. I'm out of ideas .
