I change it on import csv, random
def new_name(): with open('PL_surnames.csv', newline='') as csvfile: namesreader = csv.reader(csvfile, delimiter=' ', quotechar='|') random_choice=random.choice(namesreader) return random_choice print(new_name()) No I have this message Traceback (most recent call last): File "C:/Python31/csv", line 10, in <module> print(new_name()) File "C:/Python31/csv", line 8, in new_name random_choice=random.choice(namesreader*len(namesreader)) TypeError: object of type '_csv.reader' has no len() >>> W dniu sobota, 20 grudnia 2014 22:37:23 UTC+1 użytkownik Dariusz Mysior napisał: > > Why I get only last row from my csv file, why I don't get in any time > ranom row :/ > > import csv, random > > def new_name(): > with open('PL_surnames.csv', newline='') as csvfile: > namesreader = csv.reader(csvfile, delimiter=' ', quotechar='|') > for row in namesreader: > #print (','.join(row)) > random_choice=random.choice(row) > return random_choice > print(new_name()) > > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ca92d760-6ab0-4e06-818b-ed1b64a749b2%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.