importing fully qualified scripts to check syntax

H

horos11

hey all,

I'm trying to make a syntax checker, where I say:

python -c "import /path/to/script"

to check the syntax of the script named '/path/to/script' (note: no py
extension needed). Of course this doesn't work because the
functionality for import is bundled up with the environment..

So - is there any simple, generic way in python to import a python
file without worrying about naming convention or environment? Sort of
like require in perl?

Ed
 
G

Gabriel Genellina

I'm trying to make a syntax checker, where I say:

python -c "import /path/to/script"

to check the syntax of the script named '/path/to/script' (note: no py
extension needed). Of course this doesn't work because the
functionality for import is bundled up with the environment..

Try the py_compile module in the standard library:
http://docs.python.org/library/

The import statement does more than just checking syntax. You may want to
start the interpreter with the -tt option also.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top