1
votes

How do I declare an encoding for this code?

I know how to declare encoding in other situations but how would I do it with this?

if used_prefix and cmd=="shoot" and user.name in whitelist:
    name = args.lower()
    if name in killed:
        room.message(user.name+' is already dead.')
    else:
        killed.append(name)
        saveKills()
        room.message('//'+user.name+' shoots '+name+' in the head.')

The error message says:

SyntaxError: Non-ASCII character '\xe3' in file /home/stephen/downloads/inhaley/inhaley.py on line 6, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details.

3
Wow -- it's very negligent that a URL emitted by a built-in error message was broken when the Python website was updated. Fortunately, the new URL is easy enough to find. - Jeremy
Since the code you posted doesn't actually contain any non-ASCII codepoints, I'd suspect an exotic Unicode character snuck in; what line is line 6 here? - Martijn Pieters
@MartijnPieters It redirects to the PEP index, not to the specific PEP. That's not horrible, but it shouldn't have been much more work to do it properly. - Jeremy
@BradKoch: There is no need here to use a source encoding; all that is needed is to remove a stray character as the code itself is obviously just ASCII. - Martijn Pieters

3 Answers

0
votes

Add

#!/usr/bin/env python
# -*- coding: utf-8 -*-

On the first 2 lines.

0
votes

Add #coding=utf-8 at the top of your code, as such:

#coding=utf-8

#imports here
import math

print 'The encoding has been set!'
0
votes

put #coding=utf-8 at the top of your script/file