parsing pyton code

  • Thread starter Philippe C. Martin
  • Start date
P

Philippe C. Martin

Hi,

I'm looking for a very simple way to figure out if a line of code requires
further lines of code ex: for i in range(10): So far I have found the
following trick that seem dangerous to me since it assumes the string 'EOF'
exists in the exception message.

Do I have the right to do this ?




import compiler
import string
try:
compiler.parse('for i in range(10):')
except SyntaxError, (val1, val2):
print val1
print val2
l_eof = False
l = string.split(val1,' ')
for l_c in l:
if l_c == 'EOF':
l_eof = True
break
if l_eof == True:
print 'YES'
 

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

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top