Recently I ran into a severe problem. Whenever I would try to import modules in the Python command line shell, I’d get syntax error pointing to the first line. In fact, trying to import the module in XSI from a custom command gave a syntax error at line… zero! What the?
So I started trouble-shooting, and it finally came down to “as soon as there was a single character in the file, I would get these errors”. No matter what I would write in the file, either a “pass” statement or a # character, I would get the error. Also, while Python was reporting an error, it also gave me “no encoding declared” messages.
>>> from lighting.LightTools.modify import LT_ReorientInfiniteLight2 __main__:1: DeprecationWarning: Non-ASCII character ''\xff'' in file E:\workgroup\Data\Scripts\lighting\LightTools\modify\LT_ReorientInfiniteLight2.py o n line 1, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details Traceback (most recent call last): File "<stdin>", line 1, in ? File "E:\workgroup\Data\Scripts\lighting\LightTools\modify\LT_ReorientInfiniteLight2.py", line 1 ?p ^ SyntaxError: invalid syntax
Notice the black square before the p. That made no sense, as the p was the first character (a “pass” statement).
I tried every possible thing, like ovewriting the file with a new one, etc. Basically I spent few hours to try to solve an impossible syntax error.
However I tried another text editor (UltraEdit), and I no longer had the error. So it became clear that my first text editor, SciTE (Scintilla Text Editor), was at fault.
So in SciTE, I went to File > Encoding, and I notice it is set to one of the two UCS encodings. I set it to Default.