Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I've written this python script to list all the display_name's from a team members in Launchpad:

from launchpadlib.launchpad import Launchpad
cachedir = "/home/username/.launchpadlib/cache/"
launchpad = Launchpad.login_anonymously('just testing', 'production', cachedir)
team = launchpad.people['']
len(team.members)
for person in team.members:
   print person.display_name

exit()

But when I execute the script piping it into an output file, it fails when finding a non-ascii name:

    $ python get_list.py > /tmp/file
Traceback (most recent call last):
  File "get_list.py", line 7, in <module>
    print person.display_name
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in position 8: ordinal not in range(128)

Any ideas?

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

Use

  print person.display_name.encode('utf-8')

to tell Python what character encoding to use for unicode strings.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.