Export html NameError: name not defined (even though already defined)

psychopy 2020.2.10
Hello all,
I’m building a JS experiment with the builder.
For the loop file, I’ve set
‘condition’ + $expInfo[‘condition’] +‘.xlsx’

In experiment settings, I’ve got condition there.
image

but when I export html, I get following error messages:

Traceback (most recent call last):

  • File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\app\builder\builder.py”, line 719, in fileExport*
  • target=“PsychoJS”)*
  • File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\scripts\psyexpCompile.py”, line 73, in generateScript*
  • compileScript(infile=exp, version=None, outfile=filename)*
  • File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\scripts\psyexpCompile.py”, line 242, in compileScript*
  • _makeTarget(thisExp, outfile, targetOutput)*
  • File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\scripts\psyexpCompile.py”, line 214, in _makeTarget*
  • script = thisExp.writeScript(outfile, target=targetOutput, modular=True)*
  • File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment_experiment.py”, line 223, in writeScript*
  • self_copy.flow.writeFlowSchedulerJS(script)*
  • File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment\flow.py”, line 289, in writeFlowSchedulerJS*
  • resourceFiles = set([resource[‘rel’].replace(“\”, “/”) for resource in self.exp.getResourceFiles()])*
  • File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment_experiment.py”, line 856, in getResourceFiles*
  • condsPaths = findPathsInFile(params[‘conditionsFile’].val)*
  • File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment_experiment.py”, line 808, in findPathsInFile*
  • filePath = eval(filePath)*
  • File “”, line 1*
  • ‘condition’ + $expInfo[‘condition’] +‘.xlsx’*
  •              ^*
    

SyntaxError: invalid syntax

the porblem is very similar to
NameError: name not defined (even though it was defined earlier) - Online experiments - PsychoPy

but the solution doesn’t work for me…

I’ve tried to use a single variable for the loop file defintion, which was coded like below


image

but there still comes error msg:

Traceback (most recent call last):

  • File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment_experiment.py”, line 808, in findPathsInFile*
  • filePath = eval(filePath)*
  • File “”, line 1, in *
    NameError: name ‘usecsv’ is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  • File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\app\builder\builder.py”, line 719, in fileExport*
  • target=“PsychoJS”)*
  • File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\scripts\psyexpCompile.py”, line 73, in generateScript*
  • compileScript(infile=exp, version=None, outfile=filename)*
  • File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\scripts\psyexpCompile.py”, line 242, in compileScript*
  • _makeTarget(thisExp, outfile, targetOutput)*
  • File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\scripts\psyexpCompile.py”, line 214, in _makeTarget*
  • script = thisExp.writeScript(outfile, target=targetOutput, modular=True)*
  • File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment_experiment.py”, line 223, in writeScript*
  • self_copy.flow.writeFlowSchedulerJS(script)*
  • File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment\flow.py”, line 289, in writeFlowSchedulerJS*
  • resourceFiles = set([resource[‘rel’].replace(“\”, “/”) for resource in self.exp.getResourceFiles()])*
  • File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment_experiment.py”, line 856, in getResourceFiles*
  • condsPaths = findPathsInFile(params[‘conditionsFile’].val)*
  • File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment_experiment.py”, line 822, in findPathsInFile*
  • files.extend(findPathsInFile(str(condFile)))*
  • File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment_experiment.py”, line 839, in findPathsInFile*
  • conds = data.importConditions(thisFile[‘abs’]) # load the abs path*
  • File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\data\utils.py”, line 333, in importConditions*
  • sep=sep, dec=dec)*
  • File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\data\utils.py”, line 247, in _attemptImport*
  • sep=sep, decimal=dec)*
  • File “C:\Program Files\PsychoPy3\lib\site-packages\pandas\io\parsers.py”, line 678, in parser_f*
  • return _read(filepath_or_buffer, kwds)*
  • File “C:\Program Files\PsychoPy3\lib\site-packages\pandas\io\parsers.py”, line 446, in _read*
  • data = parser.read(nrows)*
  • File “C:\Program Files\PsychoPy3\lib\site-packages\pandas\io\parsers.py”, line 1036, in read*
  • ret = self._engine.read(nrows)*
  • File “C:\Program Files\PsychoPy3\lib\site-packages\pandas\io\parsers.py”, line 1848, in read*
  • data = self._reader.read(nrows)*
  • File “pandas_libs\parsers.pyx”, line 876, in pandas._libs.parsers.TextReader.read*
  • File “pandas_libs\parsers.pyx”, line 891, in pandas._libs.parsers.TextReader._read_low_memory*
  • File “pandas_libs\parsers.pyx”, line 945, in pandas._libs.parsers.TextReader._read_rows*
  • File “pandas_libs\parsers.pyx”, line 932, in pandas._libs.parsers.TextReader._tokenize_rows*
  • File “pandas_libs\parsers.pyx”, line 2112, in pandas._libs.parsers.raise_parser_error*
    pandas.errors.ParserError: Error tokenizing data. C error: EOF inside string starting at line 45

It would be really nice if someone could tell what’s wrong with my experiment
much much thx in advance!

Best
PJ

Hello

try
$"condition{}.xlsx".format(expInfo['condition'])

Best wishes Jens

Alternatively, try just moving the dollar sign to the start. Does your form of formatting now work online @JensBoelte ?

Hello @wakecarter

I did not test it on-line. I took the formatting from Building Experiments in PsychoPy :grinning: :wink:

Best wishes Jens

Cozy over here :). I tried a couple of approaches for exporting to online, but none worked out. Starting to suspect that variables in conditions files isn’t supported yet for online…

1 Like

You can definitely point to a variable when defining a loop online, if that’s what you mean. However, this thread contains code for doing that that I don’t recognise and feels overly complicated.

!.includes?
prompt ?

I reckon that the while loop is killing expInfo.

Hello,

I can confirm that my formatting does not work on-line. :disappointed: I just gave it a test.

@wakercarter’s solution worked. :+1:

grafik

Hello,

you might want to restrict the options a participant can chose from so that you don’t need a while-loop.

grafik

However, you need the info dialog for this.

Best wishes Jens

1 Like

Dear all,
thank you for your replies!
I’ve adapted the experiment setting as recommended
image

however, the export still doesn’t work:

with $usecsv:

Traceback (most recent call last):

  • File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment_experiment.py”, line 808, in findPathsInFile*
  • filePath = eval(filePath)*
  • File “”, line 1, in *
    NameError: name ‘usecsv’ is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  • File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\app\builder\builder.py”, line 719, in fileExport*
  • target=“PsychoJS”)*
  • File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\scripts\psyexpCompile.py”, line 73, in generateScript*
  • compileScript(infile=exp, version=None, outfile=filename)*
  • File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\scripts\psyexpCompile.py”, line 242, in compileScript*
  • _makeTarget(thisExp, outfile, targetOutput)*
  • File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\scripts\psyexpCompile.py”, line 214, in _makeTarget*
  • script = thisExp.writeScript(outfile, target=targetOutput, modular=True)*
  • File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment_experiment.py”, line 223, in writeScript*
  • self_copy.flow.writeFlowSchedulerJS(script)*
  • File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment\flow.py”, line 289, in writeFlowSchedulerJS*
  • resourceFiles = set([resource[‘rel’].replace(“\”, “/”) for resource in self.exp.getResourceFiles()])*
  • File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment_experiment.py”, line 856, in getResourceFiles*
  • condsPaths = findPathsInFile(params[‘conditionsFile’].val)*
  • File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment_experiment.py”, line 822, in findPathsInFile*
  • files.extend(findPathsInFile(str(condFile)))*
  • File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment_experiment.py”, line 839, in findPathsInFile*
  • conds = data.importConditions(thisFile[‘abs’]) # load the abs path*
  • File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\data\utils.py”, line 333, in importConditions*
  • sep=sep, dec=dec)*
  • File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\data\utils.py”, line 247, in _attemptImport*
  • sep=sep, decimal=dec)*
  • File “C:\Program Files\PsychoPy3\lib\site-packages\pandas\io\parsers.py”, line 678, in parser_f*
  • return _read(filepath_or_buffer, kwds)*
  • File “C:\Program Files\PsychoPy3\lib\site-packages\pandas\io\parsers.py”, line 446, in _read*
  • data = parser.read(nrows)*
  • File “C:\Program Files\PsychoPy3\lib\site-packages\pandas\io\parsers.py”, line 1036, in read*
  • ret = self._engine.read(nrows)*
  • File “C:\Program Files\PsychoPy3\lib\site-packages\pandas\io\parsers.py”, line 1848, in read*
  • data = self._reader.read(nrows)*
  • File “pandas_libs\parsers.pyx”, line 876, in pandas._libs.parsers.TextReader.read*
  • File “pandas_libs\parsers.pyx”, line 891, in pandas._libs.parsers.TextReader._read_low_memory*
  • File “pandas_libs\parsers.pyx”, line 945, in pandas._libs.parsers.TextReader._read_rows*
  • File “pandas_libs\parsers.pyx”, line 932, in pandas._libs.parsers.TextReader._tokenize_rows*
  • File “pandas_libs\parsers.pyx”, line 2112, in pandas._libs.parsers.raise_parser_error*
    pandas.errors.ParserError: Error tokenizing data. C error: EOF inside string starting at line 45

nor with for $“condition” + expInfo[“condition”]+ “.xlsx”
( “condition” + $expInfo[“condition”]+ “.xlsx”)

*> *
> Traceback (most recent call last):
> File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment_experiment.py”, line 808, in findPathsInFile
> filePath = eval(filePath)
> File “”, line 1, in
> NameError: name ‘expInfo’ is not defined
*> *
> During handling of the above exception, another exception occurred:
*> *
> Traceback (most recent call last):
> File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\app\builder\builder.py”, line 719, in fileExport
> target=“PsychoJS”)
> File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\scripts\psyexpCompile.py”, line 73, in generateScript
> compileScript(infile=exp, version=None, outfile=filename)
> File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\scripts\psyexpCompile.py”, line 242, in compileScript
> _makeTarget(thisExp, outfile, targetOutput)
> File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\scripts\psyexpCompile.py”, line 214, in _makeTarget
> script = thisExp.writeScript(outfile, target=targetOutput, modular=True)
> File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment_experiment.py”, line 223, in writeScript
> self_copy.flow.writeFlowSchedulerJS(script)
> File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment\flow.py”, line 289, in writeFlowSchedulerJS
> resourceFiles = set([resource[‘rel’].replace(“\”, “/”) for resource in self.exp.getResourceFiles()])
> File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment_experiment.py”, line 856, in getResourceFiles
> condsPaths = findPathsInFile(params[‘conditionsFile’].val)
> File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment_experiment.py”, line 822, in findPathsInFile
> files.extend(findPathsInFile(str(condFile)))
> File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment_experiment.py”, line 839, in findPathsInFile
> conds = data.importConditions(thisFile[‘abs’]) # load the abs path
> File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\data\utils.py”, line 333, in importConditions
> sep=sep, dec=dec)
> File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\data\utils.py”, line 247, in _attemptImport
> sep=sep, decimal=dec)
> File “C:\Program Files\PsychoPy3\lib\site-packages\pandas\io\parsers.py”, line 678, in parser_f
> return _read(filepath_or_buffer, kwds)
> File “C:\Program Files\PsychoPy3\lib\site-packages\pandas\io\parsers.py”, line 446, in _read
> data = parser.read(nrows)
> File “C:\Program Files\PsychoPy3\lib\site-packages\pandas\io\parsers.py”, line 1036, in read
> ret = self._engine.read(nrows)
> File “C:\Program Files\PsychoPy3\lib\site-packages\pandas\io\parsers.py”, line 1848, in read
> data = self._reader.read(nrows)
> File “pandas_libs\parsers.pyx”, line 876, in pandas._libs.parsers.TextReader.read
> File “pandas_libs\parsers.pyx”, line 891, in pandas._libs.parsers.TextReader._read_low_memory
> File “pandas_libs\parsers.pyx”, line 945, in pandas._libs.parsers.TextReader._read_rows
> File “pandas_libs\parsers.pyx”, line 932, in pandas._libs.parsers.TextReader._tokenize_rows
> File “pandas_libs\parsers.pyx”, line 2112, in pandas._libs.parsers.raise_parser_error
> pandas.errors.ParserError: Error tokenizing data. C error: EOF inside string starting at line 45

thank you!
but it does not work…

but the variable “usecsv” did not work either, so I also suspected that no variables are allowed in conditions files…

oddly enough:
I wanted to create a minimal example for you,
but as soon as I put the psyexp and the xlsx files into another directory, the export worked!

Could there be some kind of “local cache” for the Psychopy builder?
Anyway, the problem is solved; thank you so much!

Best wishes,
PJ

I always use Ctrl-Shift-R when rerunning the experiment after a sync.

Which version worked? Please could you mark it as the solution if you have one?