list1 = []
list2 = []
list3 = []
.
.
.
for s in list3:
if object in list1:
e = Class1(arg1, arg2, s)
else:
e = Class2(arg3, arg4, arg5, s)
x(e)
y(e)
z(e)
def my_method(self, list, e):
for object in list:
x(e)
y(e)
z(e)
然后简单地调用my_method()两次,一次为list1,一次为list2:
# How/where do I "create" e1 and e2, given I need s, which is inside my_method()?
my_method(list1, e1)
my_method(list2, e2)