Skip to content

Instantly share code, notes, and snippets.

@smathot
Created April 10, 2013 10:46
Show Gist options
  • Select an option

  • Save smathot/5353595 to your computer and use it in GitHub Desktop.

Select an option

Save smathot/5353595 to your computer and use it in GitHub Desktop.
UnicodeError fix for _stimulus.py
def __init__(self, log_comment=None):
"""Create a stimulus.
Keyword arguments:
log_comment -- the comment for the event log file (str) (optional)
"""
self._id = Stimulus._id_counter
Stimulus._id_counter += 1
log_txt = "Stimulus,created,{0},{1}".format(self.id,
self.__class__.__name__)
if log_comment is not None:
# Hack to avoid Unicode errors when Expyriment is placed in a
# location that contains special characters.
if isinstance(log_comment, str):
import sys
log_comment = log_comment.decode(sys.getfilesystemencoding())
log_txt = u"{0},{1}".format(log_txt, log_comment)
expyriment._active_exp._event_file_log(log_txt, 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment