-1

I'm not that great at python just getting snippets from here and there.

Right now I have user input, button click that runs the user's input and that is working for individual single inputs.

I am trying to make a user input with multiple answers Example "1, 2, 5, 7, 23" -> To infinity amount

When submitted I need those answers to run in a loop until they are all used up.

So 5 answers would run the loop 5 times, each time using a different number from the user input.

By "each time using a different number" I mean I will be running a modbus coil command and those integers will be the coil address. Thus turning on or off those coils via the running loop.

So something like..

usernumbers = self.txtinput.get_text()
usernumbers.split()
usernumbersamount = len(usernumbers.split()
while usernumbers <= useramount:
    modbus command goes here

Thats about as far as I can get of it will even work, Maybe it needs to be in an array for it to work?

sorry if user input looks funny this will be ran in a browser

Thanks!!

Chris
  • 1
  • 2

1 Answers1

0

If the user separates the numbers using always the same character (space for instance) you can write:

usernumbers = self.txtinput.get_text()
for coil_address in [usernumbers.split()]:
    self.run_coil_command(coil_address)

Change the split() by providing the separator used in you application: split(','), split(':'), ...

Frodon
  • 3,684
  • 1
  • 16
  • 33
  • The ending value needs to be an int, not a list. The integer will be converted into hex through the modbus library. And the command has to be sent one at a time. Its why i was asking how the list can be broken down into an infinite number because the value could be well over 100. Who would type in 100 numbers --- I don't know. – Chris Jul 21 '16 at 21:32
  • @Chris I don't understand your need. Can you be more precise on the scenario with example for each step (user input(s), desired value(s), ...) ? – Frodon Jul 21 '16 at 21:44