[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

subtraction is giving me a syntax error

Joel Pendery

3/15/2010 5:38:00 PM

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.

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
13 Answers

Richard Brodie

3/15/2010 5:43:00 PM

0


"Joel Pendery" <joel.pendery@gmail.com> wrote in message
news:56597268-3472-4fd9-a829-6d9cf51cf093@e7g2000yqf.googlegroups.com...

>> 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.


Philip Semanchuk

3/15/2010 5:49:00 PM

0


On Mar 15, 2010, at 1:37 PM, Joel Pendery wrote:

> 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.
>
> 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?


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.





MRAB

3/15/2010 6:01:00 PM

0

Joel Pendery wrote:
> 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.
>
> 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

Character '\x96' is an en-dash, which looks like a hyphen/minus sign
'-', but isn't.

Dave \Crash\ Dummy

3/15/2010 6:09:00 PM

0

On 2010-03-15, Philip Semanchuk <philip@semanchuk.com> wrote:
> On Mar 15, 2010, at 1:37 PM, Joel Pendery wrote:
>
>> 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.
[...]
>
> 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.

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

Baptiste Carvello

3/15/2010 6:44:00 PM

0

Joel Pendery a écrit :
> 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.
>
> 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

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/cc1...

Cheers,
Baptiste

Steven D'Aprano

3/15/2010 10:34:00 PM

0

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.


--
Steven

John Machin

3/15/2010 10:49:00 PM

0

On Mar 16, 5:43 am, Baptiste Carvello <baptiste...@free.fr> wrote:
> Joel Pendery a écrit :

> > 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/cc1...

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)



Dave \Crash\ Dummy

3/15/2010 10:56:00 PM

0

On 2010-03-15, Steven D'Aprano <steve@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.

--
Grant Edwards grant.b.edwards Yow! HUMAN REPLICAS are
at inserted into VATS of
gmail.com NUTRITIONAL YEAST ...

Steven D'Aprano

3/16/2010 7:48:00 AM

0

On Mon, 15 Mar 2010 22:56:19 +0000, Grant Edwards wrote:

> On 2010-03-15, Steven D'Aprano <steve@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

Dave \Crash\ Dummy

3/16/2010 2:20:00 PM

0

On 2010-03-16, Steven D'Aprano <steven@REMOVE.THIS.cybersource.com.au> wrote:

>> 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 ...