SyntaxError: Non-ASCII character

This post is from an earlier year, meaning the information here is likely outdated. You should look for a newer post from the current year to get the newest exercises and notes.

There are probably going to be a few things to watch out for in the oblig. One of these is characters not being copied correctly from the source code in the note on Jacobi’s method. A common error that Python will spew out in this case is

SyntaxError: Non-ASCII character '\xe2' in file ... on line 40, 
but no decoding declared ...

This is caused by the apostrophe ‘ being incorrectly replaced as a quotation mark ` during copying. The difference is very subtle, but for Python there is a huge difference; The apostrophe is completely legal to indicate a text string. The quotation mark is not.

The solution is to replace the offending quotation marks with apostrophes (the latter is found on the *-button on Norwegian keyboards) or to simply copy the source code manually instead.

Also, do watch out for whitespaces sneaking into your source code while copying.

Sadly, there is often many errors like these that show up when copying source code from PDF’s. Make sure you verify that the source code is the same after copying.

Leave a Reply

Your email address will not be published.