我要在“主”文件中创建几个对象,而我想做的就是使这些对象在我调用的脚本中可用。
即弥补这一点来展示方案。
if __name__ == '__main__':
import sys
received_req = appRequest()
received_req.attribute_1 = sys.argv[1]
received_req.attribute_2 = sys.argv[2]
received_req.attribute_3 = sys.argv[3]
custom_obj_1 = get_info(received_req.attribute_1) #returns me some object
custom_obj_2 = get_more_info(received_req.attribute_2) #returns me some other object
script_name = get_script_name(received_req.attribute_3) #figures out which script to run based on this attribute.
exec(open(script_name).read())
但是在被调用的脚本中,我希望有来自custom_obj_1和custom_obj_2的所有数据,以便在脚本中可以获取它们的某些属性。
所以在script_name中,可以吗...
value_need_in_script = custom_obj_1.datapoint
这可能吗?还是我的方法不正确?