y_diff = y_diff-H
is giving me the error
Syntaxerror: Non-ASCII character '\x96' in file on line 70, but no
encoding declared.
Even though I have deleted some lines before it and this line is no
longer line 70, I am still getting the error every time. I have tried
to change the encoding of the file to utf-8 but to no avail, I still
am having this issue. Any ideas?
Thanks in advance
>> y_diff = y_diff-H
>
> Syntaxerror: Non-ASCII character '\x96' in file on line 70, but no
> encoding declared.
That's likely an en-dash, not a minus sign.
0x96 is the Win1252 minus sign character. Did you copy & paste this
code from a Web browser or a word processor?
Delete the character between "y_diff" and "H" and replace it with a
plain ASCII subtraction sign.
Character '\x96' is an en-dash, which looks like a hyphen/minus sign
'-', but isn't.
I think somebody needs to stop editing his code with MS Word and start
using a programming editor. ;)
--
Grant Edwards grant.b.edwards Yow! Make me look like
at LINDA RONSTADT again!!
gmail.com
Hello,
I would say that when you press the minus key, your operating system doesn't
encode the standard (ASCII) minus character, but some fancy character, which
Python cannot interpret.
More precisely, I suspect you are unsing Windows with codepage 1252 (latin 1).
With this encoding, you have 2 kinds of minus signs: the standard (45th
character, in hex '\x2d') and the non-standard (150th character, in hex '\x96').
cf:
http://msdn.microsoft.com/en-us/library/cc195054.aspx
Cheers,
Baptiste
>> Delete the character between "y_diff" and "H" and replace it with a
>> plain ASCII subtraction sign.
>
> I think somebody needs to stop editing his code with MS Word and start
> using a programming editor. ;)
I've had this error myself, and I've never used Word to edit code. It can
happen if you copy code from a website that "helpfully" converts hyphens
to en-dashes, spaces to non-breaking spaces, or inserts ctrl-Z characters
into strings, etc. They're a devil to debug.
--
Steven
> > So I am trying to write a bit of code and a simple numerical
> > subtraction
>
> > y_diff = y_diff-H
>
> > is giving me the error
>
> > Syntaxerror: Non-ASCII character '\x96' in file on line 70, but no
> > encoding declared.
>
>
> I would say that when you press the minus key, your operating system doesn't
> encode the standard (ASCII) minus character, but some fancy character, which
> Python cannot interpret.
The likelihood that any operating system however brain-damaged and in
whatever locale would provide by default a "keyboard" or "input
method" that generated EN DASH when the '-' key is struck is somewhere
between zero and epsilon.
Already advanced theories like "used a word processor instead of a
programmer's editor" and "scraped it off the web" are much more
plausible.
> More precisely, I suspect you are unsing Windows with codepage 1252 (latin 1).
Codepage 1252 is not "latin1" in the generally accepted meaning of
"latin1" i.e. ISO-8859-1. It is a superset. MS in their wisdom or
otherwise chose to use most of the otherwise absolutely wasted slots
assigned to "C1 control characters" in latin1.
> With this encoding, you have 2 kinds of minus signs: the standard (45th
> character, in hex '\x2d') and the non-standard (150th character, in hex '\x96').
>
> cf:http://msdn.microsoft.com/en-us/library/cc195054.aspx
The above link quite correctly says that '\x96` maps to U+2013 EN
DASH. EN DASH is not any kind of minus sign.
Aside: the syndrome causing the problem is apparent with cp125x for x
in range(9)
Though it may not be Microsoft Word, I think I'd still maintain that
an editor where you can't see a ctrl-Z or tell the difference between
an ASCII minus and a windows-codepage-whatever isn't a very good
programmer's editor.
--
Grant Edwards grant.b.edwards Yow! HUMAN REPLICAS are
at inserted into VATS of
gmail.com NUTRITIONAL YEAST ...
> On 2010-03-15, Steven D'Aprano <st...@REMOVE-THIS-cybersource.com.au>
> wrote:
>> On Mon, 15 Mar 2010 18:09:29 +0000, Grant Edwards wrote:
>>
>>>> Delete the character between "y_diff" and "H" and replace it with a
>>>> plain ASCII subtraction sign.
>>>
>>> I think somebody needs to stop editing his code with MS Word and start
>>> using a programming editor. ;)
>>
>> I've had this error myself, and I've never used Word to edit code. It
>> can happen if you copy code from a website that "helpfully" converts
>> hyphens to en-dashes, spaces to non-breaking spaces, or inserts ctrl-Z
>> characters into strings, etc. They're a devil to debug.
>
> Though it may not be Microsoft Word, I think I'd still maintain that an
> editor where you can't see a ctrl-Z or tell the difference between an
> ASCII minus and a windows-codepage-whatever isn't a very good
> programmer's editor.
Regarding ctrl-Z (or for that matter other control characters), I agree
it's a lack.
As for not being able to see the difference between a hyphen and an EN-
dash, or minus sign, or whatever it is, yes but they are very similar
looking glyphs in virtually ever modern font. It would take a good eye to
see the difference between (say) ‐ ‑ and -.
--
Steven
>> Though it may not be Microsoft Word, I think I'd still maintain that
>> an editor where you can't see a ctrl-Z or tell the difference between
>> an ASCII minus and a windows-codepage-whatever isn't a very good
>> programmer's editor.
>
> Regarding ctrl-Z (or for that matter other control characters), I
> agree it's a lack.
>
> As for not being able to see the difference between a hyphen and an
> EN- dash, or minus sign, or whatever it is, yes but they are very
> similar looking glyphs in virtually ever modern font. It would take a
> good eye to see the difference between (say) ??? ??? and -.
My point is that if it's an ASCII file, then rendering \x96 as an
em-dash isn't correct. I'd expect it to show up highlighted somehow
in hex or octal so that I know it's a non-ASCII character.
--
Grant Edwards grant.b.edwards Yow! We are now enjoying
at total mutual interaction in
gmail.com an imaginary hot tub ...
>> As for not being able to see the difference between a hyphen and an
>> EN- dash, or minus sign, or whatever it is, yes but they are very
>> similar looking glyphs in virtually ever modern font. It would take a
>> good eye to see the difference between (say) ??? ??? and -.
>
> My point is that if it's an ASCII file,
source files aren't (necessary) ASCII files
--
By ZeD
OK, if it's a file with encoding <whatever>, then characters that
aren't part of <whatever> shouldn't be rendered according so some
other arbitrary character set. Illegal characters should be flagged
and displayed in a manner that makes it obvious you have illegal
characters in in the file.
If the OP was using a source file with an encoding that isn't accepted
by Python, then he needs to pick a source file encoding that is
recognized by Python.
Using a source file encoding where there are semantically _different_
characters that render identically is just asking for pain...
--
Grant Edwards grant.b.edwards Yow! I guess you guys got
at BIG MUSCLES from doing too
gmail.com much STUDYING!
Make a hex-dump of your file. How does line 70 look?
If you see
0900 66 66 96 48 0A -- ff.H.
you know you are doing something illegal.
>
>Thanks in advance
Groetjes Albert
P.S. With all due respect, error messages come not any clearer than
that!
--
--
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst