El problema es que al redefinir __init__, estas redifiniendo el constructor y con ello los miembros en ella.
Lo ideal seria hacer lo siguiente
Código python:
Ver originalimport scipy as sp
import scipy.linalg as linalg
class Solution:
def __init__(self):
self.feed_flow = 70.0
self.feed = sp.array([0.15,0.25,0.4,0.2])
self.comp_names = ("xylene", "styrene", "toluene", "benzene")
self.var=("D_1", "B_1", "D_2", "B_2")
self.xylene = sp.array([0.07,0.18,0.15,0.24])
self.styrene = sp.array([0.04,0.24,0.1,0.65])
self.toluene = sp.array([0.54,0.42,0.54,0.1])
self.benzene = sp.array([0.35,0.16,0.21,0.01])
T0_comp_frac = self.feed_flow * self.feed # component fraction on first tower (T0)
self.comp_eq = sp.array([self.xylene, self.styrene,
self.toluene, self.benzene]) #components linear equations
self.solve= sp.array(linalg.solve(self.comp_eq, T0_comp_frac))
self.D = self.solve[0] + self.solve[1]
self.B = self.solve[2] + self.solve[3]
def comp(self):
print "D= %s" % self.D
print "B= %s" % self.B
for i in range(len(self.var)):
print self.var[i], "=", self.solve[i]
flowname= ("D","B")
x = 0
while x<= 3:
y=0
z=0
while y<=2:
temp = (self.comp_eq[x,y]*self.solve[y] +
self.comp_eq[x,y+1]*self.solve[y+1])/(self.solve[y]+self.solve[y+1])
y+=2
print self.comp_names[x]+ " in "+ flowname[z]+" = ", temp
z+=1
x+=1
class Solution2(Solution):
def set_feed_flow(self, percent):
self.feed_flow = 70.0 - 70.0 * percent
if __name__=="__main__":
solution=Solution()
solution.comp()
print "*" * 80
percent = 0.01
solution2=Solution2()
solution2.set_feed_flow(0.01)
solution2.comp()
Espero haberte ayudado