NameError:名称“ random”未在python中定义错误

时间:2019-11-16 10:52:54

标签: python function

嗨,我正在尝试以Python编码执行一个函数

import os

def cre_feed(cid,question):
    import random
    #from Servay.Feed index import name_pb2
    temp_list = ["1","2","3","4","5","6","7","8","9","0","Q","W","E","R","T","Y","U","I","O","P","A","S","D","F","G","H","J","K","L","Z","X","C","V","B","N","M","q","w","e","r","t","y","u","i","o","p","a","s","d","f","g","h","j","k","l","z","x","c","v","b","n","m"]
    qid = "q" + random.choice(temp_list) + random.choice(temp_list) + random.choice(temp_list) + random.choice(temp_list)
    #f = name_pb2.names().feed_names()
    #l = len(f.names)
    #for i in list(range(0,l)):
    #    if (qid = f.names[i]):
    #        cre_feed(cid,question)
    path1 = "/Servay_app/Clients/" + str(cid) + "/" + str(cid) + "_" + str(qid) + "_feed.proto"
    file = open(path1,"w+")

我得到了这个神秘的错误

fin.cre_feed("c8596", "what is what")
Traceback (most recent call last):
  File "<pyshell#33>", line 1, in <module>
    fin.cre_feed("c8596", "what is what")
  File "/root/Documents/Servay_app/Clients/cid_feed_creater.py", line 6, in cre_feed
    temp_list = ["1","2","3","4","5","6","7","8","9","0","Q","W","E","R","T","Y","U","I","O","P","A","S","D","F","G","H","J","K","L","Z","X","C","V","B","N","M","q","w","e","r","t","y","u","i","o","p","a","s","d","f","g","h","j","k","l","z","x","c","v","b","n","m"]
NameError: name 'random' is not defined

0 个答案:

没有答案