So I'm making a program where it prints a random string of digits/letters and I want it to print onto the console as well into a text file.
print ( ''.join(random.choice(f"{letters2}{letters}{digits}") for i in range(0, option2)) )
# line above prints into console
if question == 1:
with open('passwords.txt', 'a') as f:
sys.stdout = f
print( ## )
sys.stdout = original_stdout
# I'm trying to get what it outputs to the console to print to the file aswell
Thanks