Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > syntax checker in python

Reply
Thread Tools

syntax checker in python

 
 
horos11
Guest
Posts: n/a
 
      08-07-2009
ps - I just realized that it isn't enough to do:

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

since that actually executes any statement inside of the script
(wheras all I want to do is check syntax)

So - let me reprhase that - exactly how can you do a syntax check in
python? Something like perl's -c:

perl -c script_name.p

Ed
 
Reply With Quote
 
 
 
 
Jonathan Gardner
Guest
Posts: n/a
 
      08-07-2009
On Aug 7, 1:39*pm, horos11 <(E-Mail Removed)> wrote:
> ps - I just realized that it isn't enough to do:
>
> python -c 'import /path/to/script'
>
> since that actually executes any statement inside of the script
> (wheras all I want to do is check syntax)
>
> So - let me reprhase that - exactly how can you do a syntax check in
> python? Something like perl's -c:
>
> * * *perl -c script_name.p
>


You may want to read the sections under "Python Language Services" in
the Python Library Reference. There may be something you are looking
for there.
 
Reply With Quote
 
 
 
 
Diez B. Roggisch
Guest
Posts: n/a
 
      08-08-2009
horos11 schrieb:
> ps - I just realized that it isn't enough to do:
>
> python -c 'import /path/to/script'
>
> since that actually executes any statement inside of the script
> (wheras all I want to do is check syntax)
>
> So - let me reprhase that - exactly how can you do a syntax check in
> python? Something like perl's -c:


See pylint & pychecker.

Diez

 
Reply With Quote
 
Carl Banks
Guest
Posts: n/a
 
      08-08-2009
On Aug 7, 1:39*pm, horos11 <(E-Mail Removed)> wrote:
> ps - I just realized that it isn't enough to do:
>
> python -c 'import /path/to/script'
>
> since that actually executes any statement inside of the script
> (wheras all I want to do is check syntax)
>
> So - let me reprhase that - exactly how can you do a syntax check in
> python? Something like perl's -c:
>
> * * *perl -c script_name.p


A quick and dirty way would be to use the py_compile:

python -m py_compile /path/to/script

Warning: this simply appends "c" to the filename and writes out the
compiled file (kind of dumb behavior, actually), so if it's a script
you probably want to delete it afterwards:

python -m py_compile /path/to/script ; rm -f /path/to/scriptc


A little better might be to write a little Python helper script that
directs output to nowhere (something like this, feel free to
embellish):

import py_compile
py_compile.compile(sys.argv[1],'/dev/null',None,False)



Carl Banks
 
Reply With Quote
 
nn
Guest
Posts: n/a
 
      08-10-2009
On Aug 7, 4:39*pm, horos11 <(E-Mail Removed)> wrote:
> ps - I just realized that it isn't enough to do:
>
> python -c 'import /path/to/script'
>
> since that actually executes any statement inside of the script
> (wheras all I want to do is check syntax)
>
> So - let me reprhase that - exactly how can you do a syntax check in
> python? Something like perl's -c:
>
> * * *perl -c script_name.p
>
> Ed


You might want to check PyFlakes; it doesn't execute scripts unlike
the others.

http://www.divmod.org/trac/wiki/DivmodPyflakes
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Syntax Checker that's better than the normal syntax checker Jacob Grover Ruby 5 07-18-2008 05:07 AM
Python Syntax and misspelled variable and method name checker? neerashish Python 2 05-09-2008 12:13 AM
MSN BLOCK CHECKER-MSN STATUS CHECKER-MSN PROBLEMS Pager O Rama Digital Photography 0 04-04-2006 06:58 PM
MSN BLOCK CHECKER-MSN STATUS CHECKER-MSN PROBLEMS Pager O Rama ASP General 0 04-04-2006 06:41 PM



Advertisments