0

I'm trying to make a bot. I'd like to have the ability to change variables that the bot uses while it's running without using threading. Threading isn't an option because threading and asyncio don't mix. Right now I don't have any code, it's just the concept that I need to grasp before I make this bot. But for example:

var = ("Hello")
while True:
  print(var)

I need to be able to change (in this case) "var" while the code is running without using threading.

  • 1
    The first thing that comes to mind for changing `var` in an infinite loop is threading... check this out http://stackoverflow.com/questions/28492103/how-to-combine-python-asyncio-with-threads – jkr Dec 15 '16 at 01:40
  • Didn't see that when I was writing my answer, Nice link :) -Upvote – Coolq B Dec 15 '16 at 01:48
  • So with that I'd be able to change `var` while the program ran and there wouldn't be any pause? – CoffeeWithCream Dec 15 '16 at 17:34

1 Answers1

0

Could you use:

import random

def change(var):
    var = "Hello "+chr(random.randint(65,91)) # Set var to random character from A-Z.
    return var

var = ("Hello")
while True:
    print(var)
    var = change(var)

Other than that I'd need to see the code to help more.

Coolq B
  • 344
  • 5
  • 10