import csvimport random
with open('values.csv') as f: r = csv.reader(f) header= next(r) l=list(r)
value = [x[0] for x in l]random.shuffle(value)
image = [x[1] for x in l]random.shuffle(image)
with open('random.csv', "wb") as f: csv.writer(f).writerows([header] + zip(value, image))
import csvimport operatorsample=open('random.csv', "wb")
csv1=csv.reader(sample, delimiter='.')sort= sorted(csv1, key=operator.itemgetter(0))
with open
sample=open('random.csv', "wb")
To view this discussion on the web visit https://groups.google.com/d/msgid/psychopy-users/24e2fde9-cb2a-4d52-a10b-0a7028c5804e%40googlegroups.com.--
You received this message because you are subscribed to a topic in the Google Groups "psychopy-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/psychopy-users/H8yc7WT9dcM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to psychopy-user...@googlegroups.com.
To post to this group, send email to psychop...@googlegroups.com.
Is there a way to create a numerical ascending/descending list? I tried using next(csv1, None), but it didn't seem to work.
--
You received this message because you are subscribed to a topic in the Google Groups "psychopy-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/psychopy-users/H8yc7WT9dcM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to psychopy-user...@googlegroups.com.
To post to this group, send email to psychop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/psychopy-users/E1024038-45D0-4E89-8046-9ED36F5849C0%40otago.ac.nz.
Thanks, Michael. It's working well now.Regarding the sorting action - as of now the code creates a list by looking only at the first number: 100, 125, 190, 200, 25, 250, 3...Is there a way to create a numerical ascending/descending list? I tried using next(csv1, None), but it didn't seem to work.Thanks,
----Hezi Ben Sasson
On Sun, Mar 29, 2015 at 4:53 PM, Michael MacAskill <michael....@otago.ac.nz> wrote:
> On 29/03/2015, at 11:16, HBS <hbs...@gmail.com> wrote:
>
> However, I don't see that my file has changed (that is, it wasn't sorted out). Is this because I used csv.reader and now csv.writer? Let's say that I want to save the sorted file, how would I do it?
You need to do exactly what you did in your first bit of code: (1) read in some variables from a file, (2) manipulate them, and (3) save them back to a file.
Currently, in your second code snippet you are only doing the first two steps.
Regards,
Michael
--
You received this message because you are subscribed to a topic in the Google Groups "psychopy-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/psychopy-users/H8yc7WT9dcM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to psychopy-users+unsubscribe@googlegroups.com.
To post to this group, send email to psychopy-users@googlegroups.com.
Regards,
Michael
--
You received this message because you are subscribed to a topic in the Google Groups "psychopy-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/psychopy-users/H8yc7WT9dcM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to psychopy-user...@googlegroups.com.
To post to this group, send email to psychop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/psychopy-users/CB141D42-9992-4069-ABF8-3304D1ED5CB6%40otago.ac.nz.