我有四个带有以下代码的python脚本:
主文件
from new import Name1
from new2 import Name2
class Details:
def __init__(self, id=0, vuse=True):
assert(id > 0)
self.id = id
self.vuse = vuse
def Main(self):
try:
self.dir = "/value/"
ti = Name1(id = self.id, dir = self.dir)
name = ti.getDay()
print name
except Exception, e:
print "Failed with %s" % e
if __name__ == "__main__":
at = Details(id = '1', vuse=True)
at.Main()
新的.py
class Name1:
def __init__(self,id,dir=''):
self.id = id
self.dir = dir
def getDay(self):
try:
if id == 1:
self.day = "monday"
print "Name %s" % self.day
return self.day
else:
self.day = "Another"
print "Day %s" % self.day
return self.day
except Exception, e:
print "ERROR : %s" % e
新的2.py
from find import Find
from main import Details
class Name2:
def getitems(self):
self.id = "// This value i want from main.py or new.py script"
at = Find(id = self.id )
val = at.value()
print val
if __name__ == "__main__":
a = Name2()
a.getitems()
查找.py
class Find:
def __init__(self, id):
self.id = id
def value(self):
if self.id == 1:
print "Right value"
##// Do some operation with id//
else:
print "invalid"
我的问题是我如何访问id value
new2.py 中的... new.py 也一样,我需要 id 来创建一个类的对象。