error test_suit()
Hi everyone,
I get this error message when I put the expyriment.control.run_test_suit() at the beginning of the experiment:
File "experiment.py", line 11, in <module>
control.run_test_suite()
File "C:\Users\sarah\Anaconda3\lib\site-packages\expyriment\control\_test_suite.py", line 539, in run_test_suite
from ..design import extras as _test1
File "C:\Users\sarah\Anaconda3\lib\site-packages\expyriment\design\extras\__init__.py", line 20, in <module>
from . import defaults
File "C:\Users\sarah\Anaconda3\lib\site-packages\expyriment\design\extras\defaults.py", line 26, in <module>
exec(_defaults)
File "<string>", line 1
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
I use the pathlib libary for path handling, since I have a lot of stimuli I store only the path, as a string, in each trial - as a trial_factor (when building the design) - could this lead to the problem?
Comments
Hi Sarah,
I cannot reproduce this error here. I assume that you are using Expyriment version 0.9.0? If so, it might very well be that we already fixed the error in the current master branch, and the fix will be released with the next version.
If you cannot wait that long, you can either use the 0.9.1b1 that we release some time ago, or you can install the current development snapshot directly from the master branch.
Best,
Florian
The error message you're seeing indicates that Python encountered a string with a Unicode escape sequence that is truncated, meaning it doesn't have the required number of hexadecimal digits. The position 2-3 in the error message refers to the location in the string where the error occurred.
You can solve this error "codec can't decode bytes" by using a raw string by prefixing your string with the letter "r". Raw strings don't interpret backslashes as escape characters.
path = r"C:\Users\User\Documents\file.txt"Double the backslashes in your string
path = "C:\\Users\\User\\Documents\\file.txt"Use forward slashes instead of backslashes
path = "C:/Users/User/Documents/file.txt"Unicode escape sequences can be used in both single-quoted ('...') and double-quoted ("...") strings in Python. However, it's important to note that in Python 3, strings are Unicode by default, so you can also include Unicode characters directly in a string without using escape sequences, as long as you use the appropriate character encoding.