Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add encoding utf-8 to the first line #688

Merged
merged 2 commits into from Jun 25, 2014
Merged

add encoding utf-8 to the first line #688

merged 2 commits into from Jun 25, 2014

Conversation

@stillzhl
Copy link
Contributor

@stillzhl stillzhl commented Apr 14, 2014

I am Chinese, and I need write something not english. I think the templates code should support i18n by using utf-8

@kmike
Copy link
Member

@kmike kmike commented Apr 14, 2014

Generally +1, but I think that this should be added to other template files as well, and that it should follow emacs convention (# -*- coding: utf-8 -*-).

@stillzhl
Copy link
Contributor Author

@stillzhl stillzhl commented Apr 14, 2014

OK, I will do that later and then pull another request

@nyov
Copy link
Contributor

@nyov nyov commented Apr 26, 2014

I think it looks good.
But if we add it to the templates, we have the how-verbose-should-default-templates-be discussion again. (e.g. why not add it to spider templates as well?)
/link #671, #665, #580

Since this is additional boilerplate, I usually go the route of adding an encoding line on case-by-case basis only, when ascii decoding isn't enough.
OTOH it could be good to have by default for python starters who don't know about this python convention (and then try to fix errors by using de/encode() or other wrongness).

@dangra
Copy link
Member

@dangra dangra commented Jun 3, 2014

I find per file encoding declarations awful, they have to be added to every file in your project not just the files created from templates. IMO this is better resolved by configuring editors to use UTF-8.

@kmike
Copy link
Member

@kmike kmike commented Jun 4, 2014

@dangra these comments are for Python interpreter, not for text editors. Without such line you can't have non-ascii constants (including unicode non-ascii constants) in source code.

# tst.py
print(u'Привет')
File "tst.py", line 1
SyntaxError: Non-ASCII character '\xd0' in file tst.py on line 1, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

What you can do is to configure text editor to insert such lines for new files automatically, but this doesn't work for files generated by Scrapy.

@kmike
Copy link
Member

@kmike kmike commented Jun 25, 2014

//cc @dangra this looks like a no-brainer for me, and objections to merge?

@dangra
Copy link
Member

@dangra dangra commented Jun 25, 2014

none, are you going to add the lines to the other templated files?

@kmike
Copy link
Member

@kmike kmike commented Jun 25, 2014

yep.

kmike added a commit that referenced this issue Jun 25, 2014
add encoding utf-8 to the first line
@kmike kmike merged commit df4ba41 into scrapy:master Jun 25, 2014
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants