我现在遇到的问题是用户输入被调用两次。有没有更好的方法可以更容易地在python脚本之间共享self并避免两次调用输入。我在python中读到了关于多处理模块的信息,但是无法使用它。 这是一个简短的例子:
script1.py:
class importparam(object):
def dataset1(self):
self.var1=1
self.var2=2
self.var3=3
self.var4=input('enter var4 : ')
def dataset2(self):
self.const1=11
self.const2=22
self.const3=33
self.const4 = input('enter const4 : ')
script2.py:
from main import main_
class reader_(main_):
def __init__(self):
super(reader_, self).__init__()
def addition(self):
self.add1 = self.const1+self.const2
self.add2 = self.const3+self.const4
def multiply(self):
self.mult1 = self.var1+self.var2
self.mult2 = self.var3+self.var4
main.py
from script1 import importparam
class main_(importparam):
def __init__(self):
super(main_, self).dataset1()
super(main_, self).dataset2()
def fun1(self):
from script2 import reader_
r=reader_()
val=1
if val==1:
r.addition()
else:
r.multiply()
if __name__=='__main__':
main_().fun1()