Saturday, December 20, 2014

Re: Random row

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)

On Sat, Dec 20, 2014 at 9:37 PM, Dariusz Mysior <mysior.darek@gmail.com> 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():
   
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+unsubscribe@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/07b16c6a-ca3a-4b42-8c72-33981c05d317%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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+unsubscribe@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/CAHKQagEW5MgpEWnKnrPz%2Bk%3DWKVoDpXF%3Dq8PH%3Dse1p_d8CtY-WA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment