# Using a variable file name for Conditions file of a loop

**URL:** <https://discourse.psychopy.org/t/using-a-variable-file-name-for-conditions-file-of-a-loop/20868>\
**Category:** Coding\
**Created:** [February 28, 2021, 8:38pm UTC](https://discourse.psychopy.org/t/using-a-variable-file-name-for-conditions-file-of-a-loop/20868 "2021-02-28T20:38:14Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![bwhitlow](https://avatars.discourse-cdn.com/v4/letter/b/35a633/32.png) [@bwhitlow](https://discourse.psychopy.org/u/bwhitlow)\
**Post date:** [February 28, 2021, 8:38pm UTC](https://discourse.psychopy.org/t/using-a-variable-file-name-for-conditions-file-of-a-loop/20868/1 "2021-02-28T20:38:14Z")

</div>

I have switched to 2021.1.2 and now my use of a variable descriptor for the conditions file in a loop is not acceptable. I want to indicate any of three files, which I had done with ‘trialsPearce’+$condord+’.xlsx’, where $condord was a variable in another file that had 3 values. That worked with PsychoPy3 2020, but PsychoPy now does not want a file name in quotes. How do I create a variable file name?  
Thanks!

---

<div class="post-metadata">

**Author:** ![dvbridges](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/dvbridges/32/1918_2.png) [@dvbridges](https://discourse.psychopy.org/u/dvbridges)\
**Post date:** [March 1, 2021, 12:06pm UTC](https://discourse.psychopy.org/t/using-a-variable-file-name-for-conditions-file-of-a-loop/20868/2 "2021-03-01T12:06:15Z")

</div>

@bwhitlow , have you tried

```auto
$"trialsPearce" + condord + ".xlsx" 

```

---

<div class="post-metadata">

**Author:** ![bwhitlow](https://avatars.discourse-cdn.com/v4/letter/b/35a633/32.png) [@bwhitlow](https://discourse.psychopy.org/u/bwhitlow)\
**Post date:** [March 1, 2021, 1:41pm UTC](https://discourse.psychopy.org/t/using-a-variable-file-name-for-conditions-file-of-a-loop/20868/3 "2021-03-01T13:41:25Z")

</div>

Hi David,

I have not tried that - which partly reflects my lack of a full understanding of the “$” symbol.

However, I was able to get it work by a 2-step coding process of Acond=condord, then Afile=“trialsPearce”+str(Acond)+".xlsx" and putting $Afile in the Conditions for the trials. But I will try your suggestion as well.

RIght now I’m having trouble with JS accepting the use of “expInfo” to get the condition designation when I migrate to Pavlovia.

Thanks,

Bill

---

<div class="post-metadata">

**Author:** ![dvbridges](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/dvbridges/32/1918_2.png) [@dvbridges](https://discourse.psychopy.org/u/dvbridges)\
**Post date:** [March 1, 2021, 2:20pm UTC](https://discourse.psychopy.org/t/using-a-variable-file-name-for-conditions-file-of-a-loop/20868/4 "2021-03-01T14:20:54Z")

</div>

@bwhitlow , `$` it means to treat the entry as code. Something like the following in the loop “Conditions” entry should translate ok to JS, which would create something like `"conditionA.xlsx"`:

```python
$"condition" + expInfo['myCondition'] + ".xlsx"

```

---

<div class="post-metadata">

**Author:** ![bwhitlow](https://avatars.discourse-cdn.com/v4/letter/b/35a633/32.png) [@bwhitlow](https://discourse.psychopy.org/u/bwhitlow)\
**Post date:** [March 1, 2021, 3:32pm UTC](https://discourse.psychopy.org/t/using-a-variable-file-name-for-conditions-file-of-a-loop/20868/5 "2021-03-01T15:32:25Z")

</div>

Is ‘myCondition’ the name of the field in expInfo, so the entry is what gets added to the string?

---

<div class="post-metadata">

**Author:** ![bwhitlow](https://avatars.discourse-cdn.com/v4/letter/b/35a633/32.png) [@bwhitlow](https://discourse.psychopy.org/u/bwhitlow)\
**Post date:** [March 1, 2021, 3:34pm UTC](https://discourse.psychopy.org/t/using-a-variable-file-name-for-conditions-file-of-a-loop/20868/6 "2021-03-01T15:34:29Z")

</div>

Okay, I see that it is. Thanks!

---

<div class="post-metadata">

**Author:** ![bwhitlow](https://avatars.discourse-cdn.com/v4/letter/b/35a633/32.png) [@bwhitlow](https://discourse.psychopy.org/u/bwhitlow)\
**Post date:** [March 1, 2021, 3:40pm UTC](https://discourse.psychopy.org/t/using-a-variable-file-name-for-conditions-file-of-a-loop/20868/7 "2021-03-01T15:40:42Z")

</div>

But now the effort to synch on Pavlovia crashes because expInfo is not recognized. Any thoughts on that.?

---

<div class="post-metadata">

**Author:** ![dvbridges](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/dvbridges/32/1918_2.png) [@dvbridges](https://discourse.psychopy.org/u/dvbridges)\
**Post date:** [March 1, 2021, 3:44pm UTC](https://discourse.psychopy.org/t/using-a-variable-file-name-for-conditions-file-of-a-loop/20868/8 "2021-03-01T15:44:18Z")

</div>

Where are you using `expInfo`?

---

<div class="post-metadata">

**Author:** ![bwhitlow](https://avatars.discourse-cdn.com/v4/letter/b/35a633/32.png) [@bwhitlow](https://discourse.psychopy.org/u/bwhitlow)\
**Post date:** [March 1, 2021, 6:13pm UTC](https://discourse.psychopy.org/t/using-a-variable-file-name-for-conditions-file-of-a-loop/20868/9 "2021-03-01T18:13:25Z")

</div>

I was using it in the kind of expression you suggested, but now I see that I have been mis-reading the Traceback call error box, and I will have to clarify what is causing the crash. Sorry about that.
