Python Forum
loop (create variable where name is dependent on another variable)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
loop (create variable where name is dependent on another variable)
#1
Hi guys, i am new to python. i am coding a buy/sell order instruction for interactive brokers api. Is there a way to simplify the code here?

es_nos  = 0
spy_nos = 0
nq_nos  = 1
qqq_nos = 2
rty_nos = 3
iwm_nos = 4
zb_nos  = 5
tlt_nos = 6

es_buy_sell  = 'buy' if es_nos > 0 else 'sell'
spy_buy_sell = 'buy' if spy_nos > 0 else 'sell'
nq_buy_sell  = 'buy' if nq_nos > 0 else 'sell'
qqq_buy_sell = 'buy' if qqq_nos > 0 else 'sell'
rty_buy_sell = 'buy' if rty_nos > 0 else 'sell'
iwm_buy_sell = 'buy' if iwm_nos > 0 else 'sell'
zb_buy_sell  = 'buy' if zb_nos > 0 else 'sell'
tlt_buy_sell = 'buy' if tlt_nos > 0 else 'sell'
Larz60+ write Aug-05-2022, 10:27 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time please use bbcode tags on future posts.
Reply


Messages In This Thread
loop (create variable where name is dependent on another variable) - by brianhclo - Aug-05-2022, 07:28 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  how to get variable Azdaghost 3 363 Apr-23-2025, 07:43 PM
Last Post: deanhystad
  in c# create a loop counting from 0 to 5, consecutively Frankd 19 2,345 Apr-01-2025, 12:46 PM
Last Post: Frankd
  I trying to automate the Variable Logon button using the python code but I couldn't surendrasamudrala 0 295 Mar-07-2025, 05:02 AM
Last Post: surendrasamudrala
  not able to call the variable inside the if/elif function mareeswaran 3 609 Feb-09-2025, 04:27 PM
Last Post: mareeswaran
  creating arbitrary local variable names Skaperen 9 1,867 Sep-07-2024, 12:12 AM
Last Post: Skaperen
  Variable Substitution call keys Bobbee 15 2,839 Aug-28-2024, 01:52 PM
Last Post: Bobbee
  how solve: local variable referenced before assignment ? trix 5 1,807 Jun-15-2024, 07:15 PM
Last Post: trix
  Variable being erased inside of if statement deusablutum 8 2,195 Jun-15-2024, 07:00 PM
Last Post: ndc85430
  Cant contain variable in regex robertkwild 3 1,129 Jun-12-2024, 11:50 AM
Last Post: deanhystad
  is this a valid variable name? Skaperen 6 1,751 Jun-05-2024, 10:13 PM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020