I am trying to create random digits and have them stored in a file and I did some googling and came across the pickle
function. I used it exactly how the tutorial did and now I need to know how to store all of the codes that I create in there? Here is my code
import string
import pickle
from random import randint
data = list(string.ascii_lowercase)
[data.append(n) for n in range(0, 10)]
x = [str(data[randint(0, len(data)-1)]) for n in range(0, 21)]
y = ''.join(x)
print (y)
inUse = []
inUse.append(y)
pickle.dump(inUse, open("data.pkl", "wb"))
inUse = pickle.load(open("data.pkl", "rb"))
Your way of generating
x
is overly convolutedNow, you can simply
print
x
to a file like thisIf you wish to append
N
codes to the file