Re: Random row

2014-12-22 Thread Collin Anderson
Hi, Are you sure you saved your code? There's a len() in your traceback that isn't in your code. Collin On Saturday, December 20, 2014 3:50:11 PM UTC-6, Dariusz Mysior wrote: > > I change it on > > import csv, random > > def new_name(): > with open('PL_surnames.csv', newline='') as csvfile

Re: Random row

2014-12-20 Thread Dariusz Mysior
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 thi

Re: Random row

2014-12-20 Thread Cal Leeming
Doh sorry, hit return too quickly. return random.choice(namesreader) On Sat, Dec 20, 2014 at 9:42 PM, Cal Leeming wrote: > Somewhat off-topic for django-users, this would have been better placed on > StackOverflow. > > If I understood your question correctly, I think you need to remove the > "f

Re: Random row

2014-12-20 Thread m1chael
you keep overwriting your random_choice every time the loop is run, getting the last result is expected On Sat, Dec 20, 2014 at 4:37 PM, Dariusz Mysior wrote: > 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(): > w

Re: Random row

2014-12-20 Thread Cal Leeming
Somewhat off-topic for django-users, this would have been better placed on StackOverflow. If I understood your question correctly, I think you need to remove the "for row in namesreader" and replace with; namesreader = csv.reader(csvfile, delimiter=' ', quotechar='|') return random.choice(row) O

Random row

2014-12-20 Thread Dariusz Mysior
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 (