#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

# Problem with loop items in Python 2.7 (64 bit) package

Hi,

We are using opensesame_3.3.6-py27-win64-2. We are using py2.7 to follow these steps for communicating with Stimtracker via Serial port (link to the post). Once we have resolved that issue, we were trying to create an experiment, and now we have problems when adding a Loop item to our experiment.

A Syntax error occurs:

Error message:

Traceback (most recent call last):
File "C:\Program Files (x86)\OpenSesame\Lib\site-packages\libqtopensesame\widgets\tree_overview.py", line 820, in dropEvent
self.drop_event_item_new(data, e)
File "C:\Program Files (x86)\OpenSesame\Lib\site-packages\libqtopensesame\widgets\tree_overview.py", line 719, in drop_event_item_new
item, new_items = self.drop_get_item_snippet(data)
File "C:\Program Files (x86)\OpenSesame\Lib\site-packages\libqtopensesame\widgets\tree_overview.py", line 605, in drop_get_item_snippet
catch_exceptions=False)
File "C:\Program Files (x86)\OpenSesame\Lib\site-packages\libqtopensesame\misc\qtitem_store.py", line 118, in new
allow_rename=allow_rename
File "C:\Program Files (x86)\OpenSesame\Lib\site-packages\libopensesame\item_store.py", line 211, in new
fromlist=[u'dummy']
File "C:\Program Files (x86)\OpenSesame\Lib\site-packages\libqtopensesame\items\loop.py", line 23, in <module>
from libopensesame.loop import loop as loop_runtime
File "C:\Program Files (x86)\OpenSesame\Lib\site-packages\libopensesame\loop.py", line 305
ecol = col @ (
^
SyntaxError: invalid syntax


Line 305 and around in loop.py is as follows:

# Evaluate the weights before passing them to the weight
# function, so that weights can be defined in terms of
# variables.
ecol = col @ (
lambda w: self.syntax.auto_type(self.syntax.eval_text(w))
)
try:
dm = operations.weight(ecol)
except TypeError:
raise osexception(
u'weight values should be non-negative numeric values'
)


Moreover, there seems not to be a loop.pyc file associated to the loop file in 'C://../libopensesame' (see picture).

We honestly have no clue what is happening. So could you help us?

Best wishes and "happy holidays"

• Hi Pena,

Would it be possible to connect to the Serial port with Python 3? You can look into PySerial3.4 (if you haven't already done so). Alternatively, I suppose you tried to drag & drop the loop item? Perhaps it will work when you go to experiment, and select there to add an item (the loop) to the experimental sequence.

The error message itself is a of little help for the "regular user" (and also myself). My guess would be that there is a Python2/3 conflict somewhere. Maybe @sebastiaan has an idea what is going on.

Eduard

• Hi @pena and @eduard ,

Thanks for pinging me in. The @ operator simply doesn't exist in Python 2, and it seems that I mistakenly used it anyway to fix a bug in OpenSesame 3.3.6. For now you can use OpenSesame 3.3.5, which should work. And this regression will be fixed in the next maintenance release (3.3.7). I filed an issue here.

And if it's possible to use Python 3, that would be even better, of course!

— Sebastiaan

• Hi @eduard,

I'm using py2.7 to follow these steps by @FlintMarco to communicate with Stimtracker via Serial port. I got the error missage "unicode strings are not supported, please encode to bytes" (or similar) when using the following instructions in an inline with Python 3 opensesame:

exp.serial_port.write(chr(109) + chr(104) + chr(255) + chr(0))


I tried to write the same encoding to bytes but I didn't get it. I imagine that there are many ways to solve the problem but I have not too much time and my experiment seems to work fine with Python 2, so for the moment, I will use older opensesame/Python versions.

Thnak you very much!

• Hi pena,

Ok, good luck with your experiment!

By the way, the error you describe seems to be affecting quite a few of users, but the good news is, there are also solutions: https://stackoverflow.com/questions/35642855/python3-pyserial-typeerror-unicode-strings-are-not-supported-please-encode-to

Eduard