[Compiler-sig] My code runs - but I can't 'compile' it... WHY?!

Phil Hornby phil.hornby at accutest.co.uk
Mon Aug 2 11:02:41 CEST 2004


Hi out there...

I have what seems to me like a VERY strange situation.

I have some code that I want to compile - i.e. generate a .pyc file for -
because I want to essentially hide the contents from prying eyes. The code
runs fine from a command prompt but when I try to compile it from an
interactive session of the Python interpreter as below I get the error
shown... ANY IDEAS??

"""
import compiler

compiler.compileFile('update1.py')
"""
<FYI update1.py is the file I want to compile>

"""
Traceback (most recent call last):
  File "compile.py", line 3, in ?
    compiler.compileFile('update1.py')
  File "C:\Program Files\Python23\lib\compiler\pycodegen.py", line 42, in
compileFile
    mod.compile(display)
  File "C:\Program Files\Python23\lib\compiler\pycodegen.py", line 111, in
compile
    tree = self._get_tree()
  File "C:\Program Files\Python23\lib\compiler\pycodegen.py", line 77, in
_get_tree
    tree = parse(self.source, self.mode)
  File "C:\Program Files\Python23\lib\compiler\transformer.py", line 50, in
parse
    return Transformer().parsesuite(buf)
  File "C:\Program Files\Python23\lib\compiler\transformer.py", line 120, in
parsesuite
    return self.transform(parser.suite(text))
  File "<string>", line 473

SyntaxError: invalid syntax
"""

If I simply import the code at the interactive prompt then it generates the
.pyc file with no problems - why doesn't it work from the compiler module? 

Thanks...

PS. I am using 2.3.3 - and tied to that version for the immediate future.

--
Phil



More information about the Compiler-sig mailing list