Problem defining stimulus list

Hi,

Beginner in PsychoPy trying to code an experiment in which I choose between two different stimulus lists based on being in block 1 or block 2 (specified in the expInfo). Here’s how I try to do it

if expInfo['block']==1:
    trials_2 = data.TrialHandler(nReps=5.0, method='random', 
        extraInfo=expInfo, originPath=-1,
        trialList=data.importConditions('qsnarc_1.xlsx'),
        seed=None, name='trials_2')
elif expInfo['block']==2:
     trials_2 = data.TrialHandler(nReps=5.0, method='random', 
        extraInfo=expInfo, originPath=-1,
        trialList=data.importConditions('qsnarc_2.xlsx'),
        seed=None, name='trials_2')

thisExp.addLoop(trials_2)  
thisTrial_2 = trials_2.trialList[0]

However when trying to run the script here’s what I get:

Traceback (most recent call last):
File “mypath”, line 238, in
thisExp.addLoop(trials_2) # add the loop to the experiment
NameError: name ‘trials_2’ is not defined

Experiment ended.

So it seems I cant specify trial_2 in my if-elif statements. Can anybody help?

Thanks,
Nic

Put quotes round the number.

e.g.

if expInfo['block']=='1':

Easy!
Fab, thanks a bunch.