所以,我有这个代码:
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')
Run Code Online (Sandbox Code Playgroud)
但我得到了
AttributeError: 'str' object has no attribute 'choice'
Run Code Online (Sandbox Code Playgroud)
有什么问题?