im trying to make a function in my program which gets a random name from a csv file, then prints this without repetition, when all values have been printed the array resets again (so this process can repeat).
Example code:
def generatename(currentclass):
classlistsatpath=os.path.join(ROOT_PATH,"Class name lists")
currentclass=currentclass+".csv"
currentclasspath=os.path.join(classlistsatpath,currentclass)
#this code only has to run when currentclass changes
with open(currentclasspath) as currentclassfile:
csv_reader = csv.reader(currentclassfile)
namelist=list(csv_reader)
del namelist[0]
elem=random.choice(namelist)
namelist.remove(elem)
if namelist==[]:
#get csv array again
I know this code doesn't work - I need help on something very simple xD
Thanks, Sean
Aucun commentaire:
Enregistrer un commentaire