how to print the GREEK CAPITAL LETTER delta under utf-8 encoding

人言落日是天涯,望极天涯不见家 kelvin.you at gmail.com
Tue May 29 02:46:52 EDT 2007


On 5月29日, 下午1时34分, "Martin v. Lo"wis" <mar... at v.loewis.de> wrote:
> 人言落日是天涯,望极天涯不见家 schrieb:
>
> > I lookup the utf-8 form of delta from the link.
> >http://www.fileformat.info/info/unicode/char/0394/index.htm
>
> > and then I want to print it in the python ( I work under windows)
>
> > #!/usr/bin/python
> > #coding=utf-8
>
> > print "\xce\x94"
>
> > but the result is not the 'delta' but an unknown character.
>
> I assume you print to the terminal (cmd.exe). This cannot work;
> the terminal (usually) does not interpret the characters in UTF-8.
> Instead, you should print a Unicode string, e.g.
>
> print u"\N{GREEK CAPITAL LETTER DELTA}"
>
> or
>
> print u'\u0394'
>
> This should work as long as your terminal supports printing
> the letter at all.
>
> Regards,
> Martin

yes, it could print to the terminal(cmd.exe), but when I write these
string to file. I got the follow error:

  File "E:\Tools\filegen\filegen.py", line 212, in write
    self.file.write(data)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u0394' in
position 0
: ordinal not in range(128)

but other text, in which include "chinese characters" got from
os.listdir(...),  are written to the file OK. why?




More information about the Python-list mailing list