I'm new to python. I wrote the following code, and it ran fine on one unix machine and on learnpython.org. Then I scp'd it to another machine, and I get encoding errors (below). I have searched and found many posts about encoding issues when using strings, and the use of the '# coding=utf-8" directive, however my code doesn't use any strings, it simply does a little math. Furthermore, the encoding errors seem to appear on *comment* lines. ??
python Code:
Original
- python Code |
|
|
|
#! /usr/bin/python
# This file is binsearch.py
# in order to run it, you will need to do
# "chmod u+x binsearch.py"
# at the UNIX prompt to make it executable.
# Then just run "./binsearch.py"
# at the UNIX prompt
def fofx(x):
return x**3 - 4*x**2 + x + 2.0
xlo = 0.0
xhi = 10.0
f = 999.999
tol = 1.0e-12
while (abs(f) > tol):
xmid = (xlo+xhi)/2
f = fofx(xmid)
print xlo, xhi, xmid, f
if (f > 0):
xhi = xmid
else:
xlo = xmid
The error message I get is...
% ./binsearch.py
File "./binsearch.py", line 3
SyntaxError: Non-ASCII character '\xc2' in file ./binsearch.py on line 3, but no encoding declared; see (URL blocked: see forum rules) for details
How can I change some python config file on this system to make these errors disappear? It's just a simple text file. I even copied & pasted via mouse-highlighting within a simple text editor in order to eliminate any potential "magic" invisible characters, but the error persists.
If I add the '#coding=utf-8' line -- which I believe I "shouldn't" have to do, and this is why I'm posting this thread -- then I get a new error that seems to be due to the fact that I used spaces (3 spaces, exactly, for each indent) instead of tabs. I thought spaces OR tabs were allowed. Yay or nay?
Thanks so much! I'm stumped...
% python --version
Python 2.7.3