3 ms·
First, you can place a UTF-8 byte-order marker at the beginning of your file, if your editor supports it. Secondly, you can place the following special comment
by jrockway 15y ago
First, you can place a UTF-8 byte-order marker at the beginning of your file, if your editor supports it. Secondly, you can place the following special comment in the first or second lines of your script:
# -- coding: utf-8 --
Does Python actually parse comments, or is this just to get your editor to do the right thing?
- js2 15y agoPython supports writing Unicode literals in any encoding, but you have to declare the encoding being used. This is done by including a special comment as either the first or second line of the source file: # -*- coding: latin-1 -*- The syntax is inspired by Emacs’s notation for specifying variables local to a file. Emacs supports many different variables, but Python only supports ‘coding’. The dash-splat-dash symbols indicate to Emacs that the comment is special; they have no significance to Python but are a convention. Python looks for coding: name or coding=name in the comment. http://docs.python.org/howto/unicode.html http://docs.python.org/howto/unicode.html
- stock_toaster 15y agopython specifically looks for that in the first two lines of source (to make allowance for #! stanza on the first line). See: http://www.python.org/dev/peps/pep-0263/ http://www.python.org/dev/peps/pep-0263/
- rbanffy 15y agoIt will also tolerate Vim users: # vim: set fileencoding=utf-8 http://www.python.org/dev/peps/pep-0263/ http://www.python.org/dev/peps/pep-0263/
- deleted 15y ago[deleted]