|
Hans can I ask you to explain this python code a little bit? -------------------------------------------- # Set up the replacement variables title = 'This is the title' body = '<p>This is the body</p>' # Write out the web page print template % vars() -------------------------------------------- What is "vars()"? a collection of all the variables in the current procedure? What is "%"? An argument seperator? Is the "print" function able to retrieve the names of the variables and the values also? If this is in the ballpark, can a programmer write a similar function that receives a collection of variables as a parm? Does anything prevent python from running on the iSeries? Thanks. Python looks like it is fun, but using procs, the current RPG could come close to your example like so: template = ReadSourceMemberIntoString( Srcf: SrcMbr ) ; AddToVarCollection( vars: 'Title': Title ) ; AddToVarCollection( vars: 'Body': Body ) ; ApplyVarsToTemplate( result, template, vars ) ; WriteToStdOut( result ) ; And of course if RPG was open sourced, with IBM not losing any revenue because it stays a part of websphere, then RPG could be extended in experimental ways. And the marketplace would decide if the extension is worthwhile or not. Steve Richter -----Original Message----- From: midrange-l-bounces@xxxxxxxxxxxx [mailto:midrange-l-bounces@xxxxxxxxxxxx]On Behalf Of Hans Boldt Sent: Friday, May 02, 2003 10:46 AM To: midrange-l@xxxxxxxxxxxx Subject: Re: COMMON rates (was RE: Congrads John Earl!) >Just to illustrate my point, here's how you >might code the template technique in another language, Python. >First, here's a small sample HTML template: >-------------------------------------- <html> <title>%(title)s</title> <body> <h1>%(title)s</h1> %(body)s </body> </html> -------------------------------------- Now, here's the Python code to read that template file, substitute in some replacement values, and write out the HTML: -------------------------------------- #!/usr/bin/env python # Read template file tf = file('template.text') template = tf.read() tf.close() # Set up the replacement variables title = 'This is the title' body = '<p>This is the body</p>' # Write out the web page print template % vars() --------------------------------------
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.