Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Bug report: Coding comment for Unicode literals on the SECOND line of a script
-
#!/usr/bin/env python # -*- coding: utf-8 -*- friends_with_unicode = ('Günter', 'Clauß', 'Ürsala') print('\n'.join(sorted(friends_with_unicode))) ''' If the shabang ('#!') line is the first line of the script And the coding: utf-8 line is the second line of the script Then it is recognized as a Python 2 script with unicode literals on non-Pythonista platforms (e.g. Mac OS X) But Pythonista will raise an Encoding Warning and not allow the script to run without an "Auto-Fix" option which will duplicate line 2 as the new first line of the script which breaks portability to other platforms. '''
http://docs.python.org/2/howto/unicode.html#unicode-literals-in-python-source-code says "<i>Python 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</i>"
Pythonista is currently only looking for this special comment on the first but <b>not on the second line</b> of the script.
-
This issue still seems to be present in Pythonista 1.4. Any chance that it will be fixed soon? It would be great to be able to have a command-line-runnable script that would also not make Pythonista complain about the encoding.
-
Is there a wider question of good techniques for writing scripts that could run satisfactorily from Bash, from Pythonista, and from Editorial?
-
This issue still seems to be present in Pythonista 1.4. Any chance that it will be fixed soon?
Yes, this will be fixed in 1.5.
-
@omz Terrific, thanks!
-
@MartinPacker, Once we can move to Pythonista 1.5 then starting your scripts with the following two lines will allow them to run smoothly in Linux and Mac OS X environments (bash, etc.)
#!/usr/bin/env python # -*- coding: utf-8 -*-
-
@ccc Thanks. I expect there are other gotchas for portability like how to access raw data. But maybe that's only an Editorial issue and Pythonista is in line with other Python environments.