You say: Well, it looks like the problem was that I had written the C code in an editor that saved the file with ANSI encoding.
This is exceedingly unlikely. There are no non-ASCII characters visible in your published C source. If there were any, you would have got an error message from the C compiler (except maybe if it was in a string constant; I've never tried that).
You say: Strangely, if I retyped the code in Notepad, and saved the file with UTF8 encoding, I would get compile time errors complaining about invalid characters.
Not strangely. Notepad prepends a UTF-8 BOM. This means your C compiler was being presented with a source file which started with 3 bytes of junk. Don't use Notepad. Use a proper text editor.
The indications are that the problem is much more likely to be in your Python input. The default source-file encoding in Python 3 is UTF-8. Your file contains "byte 0x89" which is not a valid UTF-8 lead byte and which the Windows cp125X encodings map to ‰
alias U+2030 PER MILLE SIGN -- either you have this in a string constant or you've typed that by mistake for a %
(PER CENT SIGN). However it's difficult to guess how you got the traceback that you did. Getting into an interpreter (e.g. IDLE) and typing import spam
should NOT give you that traceback.