Search code examples
pythonhtmlunicodeasciimako

Remove unicode characters from returned variable - Tautulli Newsletter


I want to include actors from films in my Tautulli newsletter for my Plex media collection. The newsletter template file is html and the language is mako so a mix of python, html and css.

This code returns the correct values

<p style="font-family: 'Open Sans', Helvetica, Arial, sans-serif;font-weight: 400;margin: 0;max-width: 325px;color: #ffffff;">

Actors: ${movie['actors']}

</p>

It appears like

Actors: [u'Amalia Williamson', u'Celina Martin', u'Joelle Farrow']

To be usable I'd need to remove the the unicode characters

 [u'

I have tried a couple of things and this was the most promising lead, however I couldn't get it to work.

Can anyone please amend the code so it will work please? Thank you!


Solution

  • movie['actors'] appears to be a list, so rendering it will the repr of the list and its contents. Joining the invidual strings into a lrager string should do what you want.

    >>> print u', '.join([u'Amalia Williamson', u'Celina Martin', u'Joelle Farrow'])
    Amalia Williamson, Celina Martin, Joelle Farrow
    

    In your template:

    Actors: ${u', '.join(movie['actors'])}