Hi,
win98, Py 2.3.4, wxPy 2.5.1.5
While improving my psi application, Pages Persos Chez.com ,
I faced a strange problem.
I want to run a small script like this (note the coding information):
(The script is c:\psix\a.py)
#-*- coding: iso-8859-1 -*-
def main():
for c in 'abc':
print c
print 'fin'
if __name__ == '__main__':
print 'main...'
main()
At the psi prompt, I typed
execfile('c:\\psix\a.py')
Nothing happened.
I repeated the experiment with PyShell, IDLE, DOS Python,
it was working!
At this point, I have to introduce some explanation for those
who do not know psi. Psi is a Python shell, the difference between
psi and practically all other shells lies in the fact, that psi
is not using the InteractiveInterpreter but it uses its own
--compiled source and run code-- class, called moteur. In other
words, it is not throwing each line of code to the interpreter,
but run the source as a compact block.
I isolated "moteur" and tried some more Python tests. The script
is still no working, but at least I could introduced some sys.traceback.
This indicated moteur is not compiling correctly.
So the issue is not on the side of wxPython, as I thought
Beeing confident with my class moteur (should I?) I tried more tests
with PyShell, IDLE and DOS Python.
import py_compile
py_compile.compile('c:\\psix\\a.py')
This is working ok. An a.pyc is created. Now when running script like
this
execfile('c:\\psix\\a.py')
I get, from IDLE:
__main__:1: DeprecationWarning: Non-ASCII character '\xf2' in file c:\psix\a.pyc
on line 1, but no encoding declared; see PEP 263 – Defining Python Source Code Encodings | peps.python.org
for details
Traceback (most recent call last):
File "<pyshell#3>", line 1, in -toplevel-
execfile('c:\\psix\\a.pyc')
File "c:\psix\a.pyc", line 1
;ò
^
SyntaxError: invalid syntax
Same result with DOS Python and less verbous message with PyShell.
At this point, I understood my problem, the .py file can be run
in IDLE, but not in psi because it is compiled.
I tried different encodings, no encoding, replacement of \r\n by \n, ...
always the same issue.
Pure Python issue or problems with my platform?
Does this compiling issue appears on other win plarforms?
Sorry far having been so long.
Jean-Michel Fauth, Switzerland
PS I'm using Py2.3.4, same issue under Py2.3.3