如何在Python中循环下面的代码?
How to loop the following code in Python?
我是 Python 的新手,但我尝试创建以下交易策略,但找不到针对不同产品(在本例中为交易时间)进行循环的方法。
def strategy(area_code, product, orders, environment):
order = None
new_orders = []
Quantity = 5
price_delta = 0.1
def process_flex(Plant):
order = None
Tur1 = Plant + "1"
if Tur1Volume > 0:
if Tur1Price:
order = None
if check_if_we_have_order_on_the_market(Plant,Tur1)==0:
order = package.create_sell_order(area_code, Tur1Volume, Quantity, calculate_selling_price(Tur1Price), price_delta, product, environment.current_datetime).with_label((Plant,Tur1))
if order:
new_orders.append(order)
else:
order = None
return
process_flex("bla")
process_flex("blabla")
process_flex("blablabla")
return new_orders
此代码仅适用于一种产品(1 小时),不会循环使用所有 24 种产品。
我认为它可以像这样工作:
for product in products:
Plant = ['bla', 'blabla', 'blablabla']
for i in Plant:
order = process_flex(Plant)
return_orders.append(order)
return return_orders
不幸的是,它没有用。您对解决方案有什么想法吗?
提前致谢!
您想将植物换成:
顺序 = process_flex(i)
因为 i 是 Plant
的一个元素
for product in products:
Plant = ['bla', 'blabla', 'blablabla']
for i in Plant:
order = process_flex(i)
return_orders.append(order)
return return_orders
我是 Python 的新手,但我尝试创建以下交易策略,但找不到针对不同产品(在本例中为交易时间)进行循环的方法。
def strategy(area_code, product, orders, environment):
order = None
new_orders = []
Quantity = 5
price_delta = 0.1
def process_flex(Plant):
order = None
Tur1 = Plant + "1"
if Tur1Volume > 0:
if Tur1Price:
order = None
if check_if_we_have_order_on_the_market(Plant,Tur1)==0:
order = package.create_sell_order(area_code, Tur1Volume, Quantity, calculate_selling_price(Tur1Price), price_delta, product, environment.current_datetime).with_label((Plant,Tur1))
if order:
new_orders.append(order)
else:
order = None
return
process_flex("bla")
process_flex("blabla")
process_flex("blablabla")
return new_orders
此代码仅适用于一种产品(1 小时),不会循环使用所有 24 种产品。 我认为它可以像这样工作:
for product in products:
Plant = ['bla', 'blabla', 'blablabla']
for i in Plant:
order = process_flex(Plant)
return_orders.append(order)
return return_orders
不幸的是,它没有用。您对解决方案有什么想法吗?
提前致谢!
您想将植物换成: 顺序 = process_flex(i) 因为 i 是 Plant
的一个元素 for product in products:
Plant = ['bla', 'blabla', 'blablabla']
for i in Plant:
order = process_flex(i)
return_orders.append(order)
return return_orders