0

Thats my code for a bot that answers 6 or 7 questions from another python script My question is How can I increment the Account1, so that each time i launch the script, it changes name like Account2, Account3

import subprocess
import pyautogui
import sys
import time

p = subprocess.Popen([sys.executable, 'questions.py'],
    stdin=subprocess.PIPE)
p.stdin.write(b'N\nG\n0\na\n')
p.stdin.flush()
time.sleep(15)
p.stdin.write(b'\n')
p.stdin.flush()
p.stdin.write(b'Account1\n')
p.stdin.flush()
p.stdin.write(b'white\n')
Ace
  • 53
  • 8
  • 4
    You could write the number to a txt file and update it each run? – Torin M. May 23 '19 at 19:29
  • as @TorinMay said you can use `open()`, `write()`, `read()`, `close()` to keep it in text file. Or you can use other modules to write it other formats - ie. `json` or `pickle`. – furas May 23 '19 at 19:32

1 Answers1

0

I think the simplest way would be to write this variable to a file that can be persisted across script calls.

import pickle as p

try:
    i = p.load(open("i.pickle", "rb"))
except (OSError, IOError) as e:
    i = 1

# Your code starts

p.stdin.write(bytes('Account'+str(i), encoding='utf-8')) # Replace p.stdin.write(b'Account1\n') 
i=i+1

# Your code ends

p.dump(i, open("i.pickle", "wb"))
Conor Retra
  • 169
  • 5
  • Take care where you use pickle. In this case a simple open() and readlines() would do the job. In more complicated cases use json because pickle might be a security hole depending on who can change your file i.pickle https://stackoverflow.com/a/2259351/10170240 – Manuel May 23 '19 at 19:57