×
The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.
Steve Richter wrote:
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?
Yes. More precisely, vars() is a built-in function that returns a
dictionary of all the variables in the current scope.
A better way to code this would be to code a dictionary specifically
for the replacement values to ensure separation between local
variables and substitutions, but I thought using vars() would be
easier to understand. That is, the better way to code it would be:
--------------------------------------------
# Set up the replacement variables
vars = {}
vars['title'] = 'This is the title'
vars['body'] = '<p>This is the body</p>'
# Write out the web page
print template % vars
--------------------------------------------
What is "%"? An argument seperator?
No, it is a string substitution operator. The first operand is a
string containing % expressions which are substituted by elements of
the right-hand operand. For example, "..%s.."%"abc" yields the
string "..abc..".
The right-hand operand may be a list, in which case the
substitutions go by position (much like sprintf() in C). For
example, "%s%d" %('a',17) gives you "a17".
If a dictionary is coded as right-hand operand, the substitution
variables in the left-hand string can be identified by name. For
example, "%(m)s%(n)d" % {'m':'a', 'n':17} gives you "a17".
Is the "print" function able to retrieve the names of the variables and the
values also?
I'm not sure I understand the question. The above code takes
advantage of the % operator, which is not specific to the print
statement. The print statement simply takes a list of values.
If this is in the ballpark, can a programmer write a similar function that
receives a collection of variables as a parm?
I'm not quite sure what you're asking here too, and I suspect my
answer will miss the point of your question. Python has two built-in
collection classes (to simplify a little bit): lists and
dictionaries. These, like any other objects in the language, can be
passed freely to functions.
Does anything prevent python from running on the iSeries?
Ask Per Gummedal. Or try out his iSeries port at
<http://home.no.net/pgummeda/>. I haven't tried it myself, so I
can't comment personally on its quality. But the description at the
web site seems reasonably up to date.
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 ) ;
Python is indeed a lot of fun!
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
I understand the rationale. But we'd probably need more people here
to coordinate and validate the open-source changes to assure a
reasonable level of quality.
Cheers! Hans
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 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.