Parsing Python code with a Python Program

P

pgw

Hello,

I would like to pass strings to a Python
application and have them executed as though
they were lines of code.

Is 'exec()' the function that I am looking for
and/or is there an example of this somewhere?

Thanks,

Seaweed
 
P

pw

Hello,

I had my quotes wrong is all.

EXAMPLE:

exec 'print "Hello"'

OR:

s = 'print "hello"'

exec s

Thanks anyway,

Seaweed
 
M

Michael Hudson

pgw said:
Hello,

I would like to pass strings to a Python
application and have them executed as though
they were lines of code.

Is 'exec()' the function that I am looking for
and/or is there an example of this somewhere?

Well, it's a statement, not a function, but yes, that's what you're
looking for.

Cheers,
mwh
 
I

Ivo Woltring

Well you can also generate code into a specific file name and then import
the file and execute the generated code by reference to file.function...

goodluck
Ivo
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top