Date: Mon, 13 Aug 2001 13:02:57 +0200 To: zope@zope.org From: Hamzat kamal <hamzatk@dnetsystems.net> Subject: Re: mid function! Cc: tim@freepm.com In-Reply-To: <3B762D63.54F1652B@iswt.com> References: <3.0.2.32.20010811190229.006b8dd4@dnetserver>
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,
<dtml-var dname> <dtml-if expr="_.find(dname, sub[1,6])=='Sunday'"> today is sunday </dtml-if> 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
Hamzat kamal wrote:
Date: Mon, 13 Aug 2001 13:02:57 +0200 To: zope@zope.org From: Hamzat kamal <hamzatk@dnetsystems.net> Subject: Re: mid function! Cc: tim@freepm.com In-Reply-To: <3B762D63.54F1652B@iswt.com> References: <3.0.2.32.20010811190229.006b8dd4@dnetserver>
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,
<dtml-var dname> <dtml-if expr="_.find(dname, sub[1,6])=='Sunday'"> today is sunday </dtml-if>
this is the error i received when try to view it
Error Type: AttributeError Error Value: find
pls help me out.
try _.string.find() instead of _.find(). It's a string function from the string module.
-- Jim Washington
Hamzat kamal writes:
I assumed this will serve my purpose but when i tried it, You are probably wrong... <dtml-var dname> <dtml-if expr="_.find(dname, sub[1,6])=='Sunday'"> today is sunday </dtml-if> "find" returns an index, i.e. an integer. It will always be different from a string ('Sunday').
You have been told to use the slice syntax: <dtml-if expr="dname[0:6] == 'Sunday'"> Why do you not follow this advice? You probably would start with <dtml-var expr="dname[0:6]"> to get a feeling how slicing works... You can do that in an interactive Python interpreter (to save time): python
s='your string' s[0:6]
But you can do it in DTML, too. Dieter
participants (3)
-
Dieter Maurer -
Hamzat kamal -
Jim Washington