[Zope] Re: mid function!

Tino Wildenhain tino@wildenhain.de
Mon, 13 Aug 2001 15:39:44 +0200


Hi Hamzat,

DTML is only a template language meant to place expressions
inside HTML or any text and simple floating control.
Whatever is placed in an expr=" " attribute (implicit with only "  ")
is a python expression. What you are writing in here is pure python.
However, the use of python in this expression is a bit limited for
security reasons. To make modules available to the expression,
they are appended to the namespace which is represented by an
underscore _
Available modules are whrandom, string, ...
the string module in turn defines various functions which you can use.
Refer to the python documentation for a complete list.
(http://www.python.org/  -> Documentation -> Library ... -> String Module )

Your find is available as _.string.find() inside an Expression.

However I strongly recommend not (I mean not!) use too much code
inside DTML. Try to get more familar with python (mostly the tutorial
in the documentation on python.org will do for a start)
And try to write all the logic in PythonScripts. What seems harder
at first will sure pay off in the end.

Good luck
Tino

--On Montag, 13. August 2001 13:02 +0200 Hamzat kamal <hamzatk@dnetsystems.net> wrote:

> At 02:16 AM 8/12/2001 -0500, you wrote:
>> Hamzat kamal wrote:
>>>
>>> Dear tim,
>>>
>>> I checked through the DTML function i could not find this function.
>>> I am writing a code where i will need to store the title of each dtml
>>> document with <dtml-let > and extract certain number of xters from the
>>> title and test it before calling a particular object.
>>>
>>> This function is widely used, but this is the way is been used in Vb
>>>
>>> mid(string, start [,length])
>>>   string - denote the var name
>>>   start  -   "    where you want to begin the extraction
>>>   length -   "    the no of xters you want extract from the string
>>>
>>
>> You would use the Python string module for this.
>
> I am also completely new to Python, but when checking the zope doc
> (AppendixA.htm) i saw one DTML string function
>        find(s, sub[start [,end]])
>   :- Returns the lowest index s where the substring sub is found such that
> sub is wholly contained in s[start:end].
>
> I assumed this will serve my purpose but when i tried it, this is the error
> i received when try to view it
>
>  Error Type: AttributeError
>  Error Value: find
>
> pls help me out.
>
>
>> ____________________________________________________
>> Tim Cook, President - Free Practice Management, Inc.
>> http://www.FreePM.com Office: (731) 884-4126
>> ONLINE DEMO: http://www.freepm.org:8080/FreePM
>>
>
>
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )