durusmail: quixote-users: Quixote & Python 2.1?
Quixote & Python 2.1?
2001-06-05
2001-06-05
2001-06-05
2001-06-05
PTL docs
2001-06-07
2001-06-07
2001-06-07
2001-06-07
2001-06-08
Quixote & Python 2.1?
Neil Schemenauer
2001-06-05
On Tue, Jun 05, 2001 at 05:32:12PM -0400, Goodger, David wrote:
> One more question: Are there some newbie examples or docs that I could get
> my hands on? Thanks again.

There is quxiote/demo/pages.ptl but that sucks dead bunnies
through a straw.  The good news is that PTL is almost exactly
like Python.  The only difference is that inside a template (what
is a function in Python) the result of expressions get saved as
the result of that template.  Here is one example:

    template hello():
        "hello world" # this is an expression, normally Python
                      # would discard this value but PTL
                      # appends it to the output for this
                      # template and returns it at the end

    print hello() # prints "hello"

Here is a template that does the same as the last one but
illustrations a few more rules:

    template hello2():
        greeting = "hello world" # statement, no PTL output
        None # an expression, but None gets special treatment, no output
             # everything else gets str() called on it and gets
             # appended to the output
        greeting # expression, this is included in the result

Here is a template that does the same as hello():

    template hello3():
        hello()

Perhaps we want to print a greeting a few more times:

    template ten_hellos():
        for i in range(10):
            hello()
            "\n" # PTL does not add any whitespace

Its easy to pass arguments to templates:

    template many_hellos(n):
        for i in range(n):
            hello(); "\n"

or to have conditional logic:

    template international_hello(language):
        if language == "english":
            "hello"
        elif language == "french":
            "bonjour"
        else:
            raise ValueError, "I don't speak %s" % language

As you can see, it's simple to use exceptions with PTL as well.  I
keep this little function in my PYTHONSTARTUP file:

    def ptl():
        from quixote import imphooks
        imphooks.install()

that's useful if I want to interactively play with a PTL module.
Hope that helps.

  Neil

--
"visiting malicious web sites is not real exploit scenario"
        -- secure@microsoft.com


reply