0

I am a python beginner, trying to run from power shell on vista.

when trying to call a simple script with:

python vc.py

gives error: "File "vcpy", line 1 syntaxError: Non-UTF-8 code starting with '\xff'

... where vc.py is: import sys print sys.version

It does work when I invoke instead:

cat vc.py | python

The problem with this latter approach is that it is giving us problems with the raw input function.

  • 1
    The indicated "duplicate" question does not address this issue *at all*. The linked question (and hundreds other similar) describe how to use the "# coding:" comment to indicate coding to the interpreter, but this error is thrown in response to the FIRST BYTE of the source file, before such a comment is even reached! – aldo Sep 30 '14 at 23:05
  • Ignore the supposed "duplicate" question linked above. The problem is the encoding of the source file itself (probably UTF-16 or some such). See this question and its answer: http://stackoverflow.com/q/26132121/1193893 – aldo Oct 01 '14 at 20:52

1 Answers1

2

It seems your file is started with Unicode BOM. Try to save your file in Utf-8 without BOM.

Pavel Strakhov
  • 37,133
  • 5
  • 83
  • 124
  • 1
    So is this not supported by python? I can't find anything in the documentation that says what the allowed file encoding(s) is/are! (Lots of info about declaring your encoding via '# coding:' but none of that matters if python can't get past the first byte of the file!) – aldo Sep 30 '14 at 23:02