小编scr*_*111的帖子

Python错误“str”对象没有属性“choice”

所以,我有这个代码:

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)

有什么问题?

python random attributes

0
推荐指数
1
解决办法
5697
查看次数

标签 统计

attributes ×1

python ×1

random ×1