jeudi 26 mai 2016

Python error 'str' object has no attribute 'choice'

So, I have this code:

import random, string, os, time
a = 0
random = ''
def calcular():
    global random
    random = ''.join([random.choice(string.ascii_letters) for n in xrange(4)])
    print random
while a<1:
    calcular()
    a=a+1
    pass
print time.strftime('%H:%M:%S')
os.system('pause')

But I'm getting an AttributeError: 'str' object has no attribute 'choice'. What's the problem?




Aucun commentaire:

Enregistrer un commentaire