[Tutor] Instead of *.TXT I would like to use *.CSV exported from Excel
Mitesh H. Budhabhatti
mitesh.budhabhatti at gmail.com
Fri Jul 4 07:44:07 CEST 2014
Hello Mario,
I think if you are facing the problem with shuffle, can the below solution
help:
import random
import csv
f = open('D:\\py.csv', 'r', newline='', encoding='utf8')
csvreader = csv.reader(f)
l = [row for row in csvreader] #we get rows in the file as a list using
list comprehension
random.shuffle(l)
Thanks
Warm Regards,
Mitesh H. Budhabhatti
Cell# +91 99040 83855
On Fri, Jul 4, 2014 at 6:37 AM, Mario Py <mariopy at gmx.com> wrote:
>
> OK, I'm finally getting closer.
>
> Code bellow (looks like) works if I comment out shuffle part
> But I need it to shuffle so I get random picked words.
>
> How do I get shuffle part to work?
>
>
>
> from random import shuffle
> import csv
>
> print('Write translation of Slovene word ')
> print()
>
> out=open('c:\\prevedi.csv', 'r', newline='', encoding='utf8')
> data=csv.reader(out)
>
> # shuffle(data)
>
> for line in data:
> question, rightAnswer = line
>
> answer = input(question + ' ')
> if answer.lower() != rightAnswer:
> print('Correct is: %s.' % rightAnswer,)
> print()
>
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140704/8aed4c4e/attachment.html>
More information about the Tutor
mailing list