Includeing Python in text files

P

Paolo Pantaleo

I am working on this:

I have a text file, containig certain section in the form
<?py
python code here
py?>

I parse the text file and substitute the python code with its result
[redirecting sys.stdin to a StringIO]. It something like php or
embedded perl.

So my little toy works not bad, but I was wondering if such a feature
already existed, if yes, can you point me out some links?

Thnx
PAolo
 
D

Diez B. Roggisch

Paolo said:
I am working on this:

I have a text file, containig certain section in the form
<?py
python code here
py?>

I parse the text file and substitute the python code with its result
[redirecting sys.stdin to a StringIO]. It something like php or
embedded perl.

So my little toy works not bad, but I was wondering if such a feature
already existed, if yes, can you point me out some links?

Its a templating system, and there are a gazillion out there. Some of them
are listed here:

http://www.cherrypy.org/wiki/ChoosingATemplatingLanguage


Diez
 
L

looping

Paolo said:
I am working on this:

I have a text file, containig certain section in the form
<?py
python code here
py?>

I parse the text file and substitute the python code with its result
[redirecting sys.stdin to a StringIO]. It something like php or
embedded perl.

So my little toy works not bad, but I was wondering if such a feature
already existed, if yes, can you point me out some links?

Thnx
PAolo

Like Diez had said, use a template system or you could look at COG:
http://www.nedbatchelder.com/code/cog/
 
L

Laurent Pointal

Paolo Pantaleo a écrit :
I am working on this:

I have a text file, containig certain section in the form
<?py
python code here
py?>

I parse the text file and substitute the python code with its result
[redirecting sys.stdin to a StringIO]. It something like php or
embedded perl.

So my little toy works not bad, but I was wondering if such a feature
already existed, if yes, can you point me out some links?

Yes Python Inside HTML, like this example from Karrigell docs
( http://karrigell.sourceforge.net/en/pythoninsidehtml.htm ):

The current date is
<% import time
print time.strftime("%d:%m:%y",time.localtime(time.time()))
%>


See http://karrigell.sourceforge.net/

A+

Laurent.
 
E

Erik Max Francis

Paolo said:
I am working on this:

I have a text file, containig certain section in the form
<?py
python code here
py?>

I parse the text file and substitute the python code with its result
[redirecting sys.stdin to a StringIO]. It something like php or
embedded perl.

So my little toy works not bad, but I was wondering if such a feature
already existed, if yes, can you point me out some links?

Another standalone templating system is EmPy:

http://www.alcyone.com/software/empy/
 
C

Chris Smith

Diez said:
Paolo Pantaleo wrote:

I am working on this:

I have a text file, containig certain section in the form
<?py
python code here
py?>

I parse the text file and substitute the python code with its result
[redirecting sys.stdin to a StringIO]. It something like php or
embedded perl.

So my little toy works not bad, but I was wondering if such a feature
already existed, if yes, can you point me out some links?


Its a templating system, and there are a gazillion out there. Some of them
are listed here:

http://www.cherrypy.org/wiki/ChoosingATemplatingLanguage


Diez
I'm just getting into programming so this may be a dumb question...but
why would you want to do this? What is templating good for?

Chris
 
P

Paolo Pantaleo

2006/5/23 said:
Diez said:
Paolo Pantaleo wrote:

I am working on this:

I have a text file, containig certain section in the form
<?py
python code here
py?>

I parse the text file and substitute the python code with its result
[redirecting sys.stdin to a StringIO]. It something like php or
embedded perl.

So my little toy works not bad, but I was wondering if such a feature
already existed, if yes, can you point me out some links?


Its a templating system, and there are a gazillion out there. Some of them
are listed here:

http://www.cherrypy.org/wiki/ChoosingATemplatingLanguage


Diez
I'm just getting into programming so this may be a dumb question...but
why would you want to do this? What is templating good for?

Chris
Well php is base on this principle, most (server side) dynamic sites
are based on some template sistem

PAolo
 

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,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top