# Randomizing trials name error

**URL:** <https://discourse.psychopy.org/t/randomizing-trials-name-error/23845>\
**Category:** Coding\
**Created:** [July 2, 2021, 3:12pm UTC](https://discourse.psychopy.org/t/randomizing-trials-name-error/23845 "2021-07-02T15:12:26Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![\_junaid123](https://avatars.discourse-cdn.com/v4/letter/_/dfb087/32.png) [@\_junaid123](https://discourse.psychopy.org/u/_junaid123)\
**Post date:** [July 2, 2021, 3:12pm UTC](https://discourse.psychopy.org/t/randomizing-trials-name-error/23845/1 "2021-07-02T15:12:26Z")

</div>

I am attempting to randomize 16 conditions in my excel file across 64 faces in my excel file. the 16 conditions take up two rows in the excel file, so I am randomizing two lists of stimuli labelled SelfGain and Charitygain. I used the code from this video but adjusted it for my experiment: [Using Code to Randomize Two Lists of Stimuli within a Single Loop -- PsychoPy Mini Tutorials - YouTube](https://www.youtube.com/watch?v=toQ2enxAv1E)

I keep encountering the same error in my code over and over again:  
textSelfGain.setText(SelfGain[Cur\_Self]  
NameError: name ‘Cur\_Self’ is not defined

This happens with all the variables. I am not sure how to fix this.

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [July 2, 2021, 4:39pm UTC](https://discourse.psychopy.org/t/randomizing-trials-name-error/23845/2 "2021-07-02T16:39:03Z")

</div>

> [@\_junaid123](#):
>
> NameError: name ‘Cur\_Self’ is not defined

Where does Cur\_Self come from?

---

<div class="post-metadata">

**Author:** ![\_junaid123](https://avatars.discourse-cdn.com/v4/letter/_/dfb087/32.png) [@\_junaid123](https://discourse.psychopy.org/u/_junaid123)\
**Post date:** [July 2, 2021, 4:47pm UTC](https://discourse.psychopy.org/t/randomizing-trials-name-error/23845/3 "2021-07-02T16:47:06Z")

</div>

Hi!

Thanks for your reply. I actually ended up figuring this out. I am wondering, do you have any idea how to randomize 16 trials across an excel sheet that has 64 conditons, so that each of the 16 conditions only appears 4 times?

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [July 2, 2021, 5:47pm UTC](https://discourse.psychopy.org/t/randomizing-trials-name-error/23845/4 "2021-07-02T17:47:36Z")

</div>

Have a look at my independent randomisation online demo.

---

<div class="post-metadata">

**Author:** ![\_junaid123](https://avatars.discourse-cdn.com/v4/letter/_/dfb087/32.png) [@\_junaid123](https://discourse.psychopy.org/u/_junaid123)\
**Post date:** [July 2, 2021, 6:58pm UTC](https://discourse.psychopy.org/t/randomizing-trials-name-error/23845/5 "2021-07-02T18:58:16Z")

</div>

When I try to use the demo you have i get this error:

TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [July 2, 2021, 7:21pm UTC](https://discourse.psychopy.org/t/randomizing-trials-name-error/23845/6 "2021-07-02T19:21:22Z")

</div>

Do you mean when you try your own copy of it? It works when I try it here: [independent-randomisation [PsychoPy]](https://run.pavlovia.org/vespr/independent-randomisation/)

Please could you check the error in the console to find out which variable is NoneType?

---

<div class="post-metadata">

**Author:** ![\_junaid123](https://avatars.discourse-cdn.com/v4/letter/_/dfb087/32.png) [@\_junaid123](https://discourse.psychopy.org/u/_junaid123)\
**Post date:** [July 2, 2021, 7:21pm UTC](https://discourse.psychopy.org/t/randomizing-trials-name-error/23845/7 "2021-07-02T19:21:38Z")

</div>

nope sorry, when i use it in my own study; this is the full error

listA.append(str(int(SelfGain)))  
TypeError: int() argument must be a string, a bytes-like object or a number, not ‘NoneType’

##### Experiment ended.

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [July 2, 2021, 7:30pm UTC](https://discourse.psychopy.org/t/randomizing-trials-name-error/23845/8 "2021-07-02T19:30:49Z")

</div>

So the problem is with SelfGain. Where does that come from?

---

<div class="post-metadata">

**Author:** ![\_junaid123](https://avatars.discourse-cdn.com/v4/letter/_/dfb087/32.png) [@\_junaid123](https://discourse.psychopy.org/u/_junaid123)\
**Post date:** [July 2, 2021, 7:33pm UTC](https://discourse.psychopy.org/t/randomizing-trials-name-error/23845/9 "2021-07-02T19:33:45Z")

</div>

![spreadsheet](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/9/f/9f03c37e1ab5a51ecb5b60f803a16b04fc9ac1ea.png)

SelfGain and Charitygain are the two lists of stimuli that I am trying to randomize. Together they make up 16 conditions, that I want to repeat 4 times across 64 faces in a random order.

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [July 2, 2021, 7:40pm UTC](https://discourse.psychopy.org/t/randomizing-trials-name-error/23845/10 "2021-07-02T19:40:47Z")

</div>

Are you using 0:16 to select the correct rows?

Dollars confuse PsychoPy. I would remove them from the spreadsheet and add them to the display text directly.

(or put the contents of those cells in quotes)

---

<div class="post-metadata">

**Author:** ![\_junaid123](https://avatars.discourse-cdn.com/v4/letter/_/dfb087/32.png) [@\_junaid123](https://discourse.psychopy.org/u/_junaid123)\
**Post date:** [July 2, 2021, 7:42pm UTC](https://discourse.psychopy.org/t/randomizing-trials-name-error/23845/11 "2021-07-02T19:42:27Z")

</div>

yup i selected 0:16

the dollars aren’t in my spreadsheet that’s actually in my experiment because they weren’t showing up on the display anyways.

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [July 2, 2021, 7:46pm UTC](https://discourse.psychopy.org/t/randomizing-trials-name-error/23845/12 "2021-07-02T19:46:21Z")

</div>

If that’s not the spreadsheet you’re using then please could you upload the one you are?

---

<div class="post-metadata">

**Author:** ![\_junaid123](https://avatars.discourse-cdn.com/v4/letter/_/dfb087/32.png) [@\_junaid123](https://discourse.psychopy.org/u/_junaid123)\
**Post date:** [July 2, 2021, 7:48pm UTC](https://discourse.psychopy.org/t/randomizing-trials-name-error/23845/13 "2021-07-02T19:48:00Z")

</div>

[Face stimuli list Giving choices study.xlsx](https://discourse.psychopy.org/uploads/short-url/yKN7xDTlGTjCATehBXOwDlWt1U4.xlsx) (16.1 KB)

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [July 2, 2021, 7:59pm UTC](https://discourse.psychopy.org/t/randomizing-trials-name-error/23845/14 "2021-07-02T19:59:34Z")

</div>

That looks fine (apart from the cursor being in an empty cell but I think that should be okay in this instance).

What tab is your code in?

I would add print(“SelfGain”,SelfGain) just above the error to see what value is shown in the developer console.

---

<div class="post-metadata">

**Author:** ![\_junaid123](https://avatars.discourse-cdn.com/v4/letter/_/dfb087/32.png) [@\_junaid123](https://discourse.psychopy.org/u/_junaid123)\
**Post date:** [July 2, 2021, 8:08pm UTC](https://discourse.psychopy.org/t/randomizing-trials-name-error/23845/15 "2021-07-02T20:08:15Z")

</div>

I have it in begin routine, the same way that it’s shown in your demo. Not exactly sure where to type in the print(“SelfGain”,SelfGain), the runner shows the error and doesn’t let me type anything.

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [July 2, 2021, 8:14pm UTC](https://discourse.psychopy.org/t/randomizing-trials-name-error/23845/16 "2021-07-02T20:14:23Z")

</div>

The print statement goes in Begin Routine, just above listA.append. If you get an error on the JS side, try retyping the quotes.

---

<div class="post-metadata">

**Author:** ![\_junaid123](https://avatars.discourse-cdn.com/v4/letter/_/dfb087/32.png) [@\_junaid123](https://discourse.psychopy.org/u/_junaid123)\
**Post date:** [July 2, 2021, 8:17pm UTC](https://discourse.psychopy.org/t/randomizing-trials-name-error/23845/17 "2021-07-02T20:17:51Z")

</div>

![ss2](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/1/a/1ae2956f8c76bef8d12f9cad307f43c22208753f.png)  
 ![ss1](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/3/a/3a128bff50a7fe986434fcbc44b8fcb7ba004788.png)

This is what I got

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [July 2, 2021, 8:31pm UTC](https://discourse.psychopy.org/t/randomizing-trials-name-error/23845/18 "2021-07-02T20:31:32Z")

</div>

That’s really useful. It means that most of the cells are working. I still think it’s picking up the wrong rows. You could load them sequentially and then shuffle the list afterwards or you could split those columns into a new spreadsheet.

The easiest first test would be just to turn off the randomisation of the loop (and double check the contents of “selected rows”).

It might be that you need to have a value in row 18 even though you aren’t going to use it – maybe put a dummy value like 999.

---

<div class="post-metadata">

**Author:** ![\_junaid123](https://avatars.discourse-cdn.com/v4/letter/_/dfb087/32.png) [@\_junaid123](https://discourse.psychopy.org/u/_junaid123)\
**Post date:** [July 2, 2021, 8:54pm UTC](https://discourse.psychopy.org/t/randomizing-trials-name-error/23845/19 "2021-07-02T20:54:02Z")

</div>

When I do it sequentially the transfers load onto the screen, but when i select random there are no numbers presented even when i add a dummy value. Even though the cells are working they aren’t being presented on the screen when its presented at random.
