Not quite sure how to ask this but let me just explain.
import random
import string.ascii_uppercase
chars = string.as
def random_string():
return "".join([random.choice(chars) + " " for i in range(10])
print(random_string())
f = open("test.txt", "a+")
f.write(random_string())
f.close()
in my example print
and f.write
will both perform an operation with a different string, how can I make it so f.write
writes the same string as gets printed, and then when print
gets called again it creates a new string and f.write
follows.