Python Forum
I'm afraid it is a question of copyright
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I'm afraid it is a question of copyright
#1
To Metulburr. Hi, On the terminal I tried first : pong$ python game.py....It runs well. Second I tried (always on the terminal): ping$ python game.py........There it does not work. " no ASCII character 'xc2' in file /data/GUI/button.py in line 60" .....I go there and on line 60 I find  'c' in a circle...2017. Pycharm says( on the output): "but no encoding declared see: http://python.org/dev/peps/........: Even if I delete(comment)  line 60 it does not work. Can you help me ? Do you know anyone that succeeded what I am trying to do  ??
Reply
#2
Quote: I tried first : pong$ python game.py....It runs well. Second I tried (always on the terminal): ping$ python game.py........There it does not work. " no ASCII character 'xc2' in file /data/GUI/button.py in line 60"

Im not sure what you are doing. The $ is the prompt symbol where everything before it is the path, and after is the command. Im not sure why one would be pong and one would be ping???

And what does this have anything to do with copyright?
Recommended Tutorials:
Reply
#3
I believe he is referring to the 'copyright' symbol ©

@sylas, you need to post the entire error code from the command terminal, not that supplied by Pycharm.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#4
Here it is:sylvain@sylvain-HP-Mini-110-1100:~/PycharmProjects$ cd ping;ls
data  game.exe  game.py  LICENSE  readme.md  resources  setup.py
sylvain@sylvain-HP-Mini-110-1100:~/PycharmProjects/ping$ python game.py
Traceback (most recent call last):
  File "game.py", line 5, in <module>
    from data.main import main
  File "/home/sylvain/PycharmProjects/ping/data/main.py", line 3, in <module>
    from .control import Control
  File "/home/sylvain/PycharmProjects/ping/data/control.py", line 4, in <module>
    from .states import (classic, menu, mode, options, controls, audio, ghost, splash, keybinding, getkey)
  File "/home/sylvain/PycharmProjects/ping/data/states/keybinding.py", line 5, in <module>
    from ..GUI import button
  File "/home/sylvain/PycharmProjects/ping/data/GUI/button.py", line 60
SyntaxError: Non-ASCII character '\xc2' in file /home/sylvain/PycharmProjects/ping/data/GUI/button.py on line 60, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
sylvain@sylvain-HP-Mini-110-1100:~/PycharmProjects/ping$
Reply
#5
did you change the code?
Recommended Tutorials:
Reply
#6
Add:
# -*- coding: utf-8 -*-
as the very first line of your code
Reply
#7
(Sep-22-2017, 12:53 PM)Larz60+ Wrote: Add:
# -*- coding: utf-8 -*-
as the very first line of your code
Does PyCharm require this?
Recommended Tutorials:
Reply
#8
Not part of PyCharm
I'm thinking This is a windows thing. I ran into it when I was converting the old forum MySql,
There are three utf codes that for whatever bonehead reason are not part of their
standard utf character set.
Quote:Many web pages marked as using the ISO-8859-1 character encoding actually use the similar Windows-1252 encoding, and web browsers will interpret ISO-8859-1 web pages as Windows-1252. Windows-1252 features additional printable characters, such as the Euro sign (€) and curly quotes (“ ”), instead of certain ISO-8859-1 control characters. This function will not convert such Windows-1252 characters correctly. Use a different function if Windows-1252 conversion is required.
Reply
#9
(Sep-22-2017, 12:54 PM)metulburr Wrote: Does PyCharm require this?

No it is not required by pycharm. Pycharm does have an option as to what type of encoding you want to use to 'save' and 'read' a file.

@Larz60+
Quote:as the very first line of your code

I'm taking a guess that sylas is using Linux, in which case, his first line should be the 'shebang' line followed by the 'encoding' line.

To be honest, with all the changes Python has made (including those for Windows) with utf-8, I'm not sure that line is even useful anymore. I'd have to check the latest docs.

I'll be honest, I have not read the code, but I presume a change has been made to one of the files either in directory 'pong' or directory 'ping'.

EDIT: O.K., since Python 3.0 +, the default is UTF-8, so line is only required if you wish to deviate from that. Version 2.x still requires it.

From 3.6.2 docs
Quote:You can use a different encoding from UTF-8 by putting a specially-formatted comment as the first or second line of the source code:

# -*- coding: <encoding name> -*-

From the 2.7 doc:
Quote:If you don’t include such a comment, the default encoding used will be ASCII. Versions of Python before 2.4 were Euro-centric and assumed Latin-1 as a default encoding for string literals; in Python 2.4, characters greater than 127 still work but result in a warning. Version 2.5 and higher result in a Syntax error.

Apologies Larz, depending on the Python version Sylas is running, it may just indeed be required.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#10
# -*- coding: utf-8 -*- was needed in Python 2 to set source encoding to UTF-8.
Python 2 has default ASCII encoding,Python 3.x has default UTF-8 encoding.
So using that line only make sense if using Python 2,
or want to deviate from the default UTF-8 in Python 3 eg # -*- coding: latin-1 -*-.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020