# Displaying unicode text strings in Psychopy 3

**URL:** https://discourse.psychopy.org/t/displaying-unicode-text-strings-in-psychopy-3/10195
**Category:** Builder
**Created:** [December 5, 2019, 6:33pm UTC](https://discourse.psychopy.org/t/displaying-unicode-text-strings-in-psychopy-3/10195 "2019-12-05T18:33:48Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Lyam\_Bailey](https://avatars.discourse-cdn.com/v4/letter/l/e79b87/32.png) [@Lyam\_Bailey](https://discourse.psychopy.org/u/Lyam_Bailey)
#### Post date: [December 5, 2019, 6:33pm UTC](https://discourse.psychopy.org/t/displaying-unicode-text-strings-in-psychopy-3/10195/1 "2019-12-05T18:33:48Z")

</div>

Dear users

I am building a simple experiment in which a series of words are presented onscreen for 3 seconds each. I am implementing this in Builder, using a Text object to display the words.

I need the second letter of each word to be underlined. Note that I plan to use a list of words read from an excel sheet, but for the purposes of debugging I’m ignoring the excel sheet and just trying to present the word “hello”.

So far I’ve taken a unicode-based approach, for example:

> print(‘h\u0332ello’)

This works in PsychoPy’s Coder View: see screenshot below

![Capture](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/6/e/6ef1febe869e840c2a02e47eaccc67af90863efa.png)

However when I use this code in the builder it fails. I have tried pasting `print('h\u0332ello')` directly into the Text field of the Text object, which results in PsychoPy literally displaying “h\u0332ello” onscreen. I have also tried entering `$word` into the text field, and then defining `word` as `word = print('h\u0332ello')` in a code snippet. This latter approach causes the following error:

`UnicodeEncodeError: 'charmap' codec can't encode character '\u0332' in position 3: character maps to <undefined>`

Can anybody recommend a way to get this working?

---

<div class="post-metadata">

### Author: ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)
#### Post date: [December 5, 2019, 9:39pm UTC](https://discourse.psychopy.org/t/displaying-unicode-text-strings-in-psychopy-3/10195/2 "2019-12-05T21:39:12Z")

</div>

```
$'h\u0332ello'

```

although for me that underlines the _h_ rather than the _e_, but I don’t know enough about unicode to know if that is correct or not.

```
$'he\u0332llo'

```

underlines the _e_ for me.

Using `print()` in any way in Builder components is not going to work. `print()` is a Python command that sends output to the console. It can’t do anything meaningful to stimuli displayed in a PsychoPy window.

All assuming that you are using the Python 3 version of PsychoPy - Python 3 deals natively with unicode strings, unlike Python 2.

If you want to programatically underline the second letter using a variable from a conditions file (called, say `word`), you could put this in your text field:

```
 $word[0:2] + '\u0332' + word[2:]
```

---

<div class="post-metadata">

### Author: ![Lyam\_Bailey](https://avatars.discourse-cdn.com/v4/letter/l/e79b87/32.png) [@Lyam\_Bailey](https://discourse.psychopy.org/u/Lyam_Bailey)
#### Post date: [December 6, 2019, 5:06pm UTC](https://discourse.psychopy.org/t/displaying-unicode-text-strings-in-psychopy-3/10195/3 "2019-12-06T17:06:35Z")

</div>

@Michael, thanks for the reply! I tried implementing your suggestions (both `$'he\u0332llo'` and `$word[0:2] + '\u0332' + word[2:]`), both cause the experiment to crash and give the following error:

> TypeError: ord() expected a character, but string of length 2 found

**EDIT:**  
Some additional info: yes, I am using the Python 3 version (specifically, PsychoPy version 3.2.4). Running on Windows 10.

---

<div class="post-metadata">

### Author: ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)
#### Post date: [December 8, 2019, 2:27am UTC](https://discourse.psychopy.org/t/displaying-unicode-text-strings-in-psychopy-3/10195/4 "2019-12-08T02:27:52Z")

</div>

It works for me, so this is a bit puzzling. I think you would need to post a minimal example so that the issue can be replicated (i.e. a .psyexp file showing nothing but this issue).

---

<div class="post-metadata">

### Author: ![Lyam\_Bailey](https://avatars.discourse-cdn.com/v4/letter/l/e79b87/32.png) [@Lyam\_Bailey](https://discourse.psychopy.org/u/Lyam_Bailey)
#### Post date: [December 9, 2019, 6:10pm UTC](https://discourse.psychopy.org/t/displaying-unicode-text-strings-in-psychopy-3/10195/5 "2019-12-09T18:10:22Z")

</div>

Hi Michael,

Here is a simplified version of the experiment that has a single routine, containing only a text object with `$'h\u0332ello`’ in the Text field. This produces the problem described above (on my computer, at least!)

[pilot\_2.psyexp](https://discourse.psychopy.org/uploads/short-url/88SvPeGkcuVEusS3l5Xfor4fz3f.psyexp) (4.1 KB)

---

<div class="post-metadata">

### Author: ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)
#### Post date: [December 9, 2019, 10:20pm UTC](https://discourse.psychopy.org/t/displaying-unicode-text-strings-in-psychopy-3/10195/6 "2019-12-09T22:20:46Z")

</div>

It works fine for me. Just to be absolutely sure, can you switch to the Coder view and type this in the Shell tab, and let us know the output?

```auto
import sys
sys.version

```

---

<div class="post-metadata">

### Author: ![Lyam\_Bailey](https://avatars.discourse-cdn.com/v4/letter/l/e79b87/32.png) [@Lyam\_Bailey](https://discourse.psychopy.org/u/Lyam_Bailey)
#### Post date: [December 12, 2019, 3:58pm UTC](https://discourse.psychopy.org/t/displaying-unicode-text-strings-in-psychopy-3/10195/7 "2019-12-12T15:58:03Z")

</div>

How puzzling. Here is the output you requested:

> ‘3.6.6 (v3.6.6:4cf1f54eb7, Jun 27 2018, 03:37:03) [MSC v.1900 64 bit (AMD64)]’

---

<div class="post-metadata">

### Author: ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)
#### Post date: [December 12, 2019, 11:19pm UTC](https://discourse.psychopy.org/t/displaying-unicode-text-strings-in-psychopy-3/10195/8 "2019-12-12T23:19:55Z")

</div>

OK so I’m a bit lost then. I am using a Mac but wouldn’t think that this should be an operating system- related thing. But can’t suggest anything else at this stage. Hopefully someone else has something to contribute?

---

<div class="post-metadata">

### Author: ![dvbridges](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/dvbridges/32/1918_2.png) [@dvbridges](https://discourse.psychopy.org/u/dvbridges)
#### Post date: [December 13, 2019, 12:05pm UTC](https://discourse.psychopy.org/t/displaying-unicode-text-strings-in-psychopy-3/10195/9 "2019-12-13T12:05:18Z")

</div>

How about printing out the system encoding in both Builder and Coder, it may shed some light on what is happening:

```auto
import sys
print(sys.getdefaultencoding)

```
