i'm not very knowledgeable in the ways of python, but i've found out how to split strings by separators : for example : <dtml-if expr="_.string.split(_['REMOTE_ADDR'],'.')[1] == '71'">etc... how do i reference the *last* character of a string, not using any separators ?? -- Geir B Hansen web-developer/designer geirh@funcom.com http://www.funcom.com
Geir B Hansen wrote:
i'm not very knowledgeable in the ways of python,
The Python tutorial and the standard library reference which you can get at www.python.org are highly recommended!
but i've found out how to split strings by separators : for example : <dtml-if expr="_.string.split(_['REMOTE_ADDR'],'.')[1] == '71'">etc...
how do i reference the *last* character of a string, not using any separators ??
I'm not quite sure what you mean by 'the last character of a string, not using any separators', but 'the last character of a string', I can answer: if s is a string, then: s[-1] refers to its last character. Regards, Martijn
on 6. january 2000 Martijn Faassen wrote : [snip] MF> I'm not quite sure what you mean by 'the last character of a string, not MF> using any separators', but 'the last character of a string', I can MF> answer: MF> if s is a string, then: MF> s[-1] MF> refers to its last character. thanks.. exactly what i needed.. I'll check out the tutorials on python.org now.. I figure i have to learn python properly to get the most out of zope.. (and i'll take more care explaining what i mean next time.. I managed to confuse 2 out of 2 people answering me this time.. hmm.. must drink more coffee, i think.. -- Geir B Hansen web-developer/designer geirh@funcom.com http://www.funcom.com
hi geir, i assume you're referring to the last element of the split-up string, not the last character, right? if i remember right from those great o'reilly books about python the last element in a list (which is what you get from a split operation) can be referred to by <mylistname>[-1], so your example would look like: <dtml-if expr="_.string.split(_['REMOTE_ADDR'],'.')[-1] == '71'"> this works because you can count up from the first element ([0], [1] etc) or down from the last ([-1], [-2]) by using negative indexes. jens
-----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Geir B Hansen Sent: Thursday, January 06, 2000 06:01 To: zope@zope.org Subject: [Zope] splitting strings ??
i'm not very knowledgeable in the ways of python, but i've found out how to split strings by separators : for example : <dtml-if expr="_.string.split(_['REMOTE_ADDR'],'.')[1] == '71'">etc...
how do i reference the *last* character of a string, not using any separators ??
-- Geir B Hansen web-developer/designer geirh@funcom.com http://www.funcom.com
on 6. januar 2000 Jens Vagelpohl wrote : JV> hi geir, JV> i assume you're referring to the last element of the split-up string, not JV> the last character, right? JV> if i remember right from those great o'reilly books about python the last JV> element in a list (which is what you get from a split operation) can be JV> referred to by <mylistname>[-1], so your example would look like: JV> <dtml-if expr="_.string.split(_['REMOTE_ADDR'],'.')[-1] == '71'"> JV> this works because you can count up from the first element ([0], [1] etc) or JV> down from the last ([-1], [-2]) by using negative indexes. JV> jens thanks for the info about the negative numbers (nice to know), but i am actually looking for the last character of a string.. sorry for my lousy explanation in the first mail. i'll get the o'reilley-book on python as fast as i can.. Promise !! -- Geir B Hansen web-developer/designer geirh@funcom.com http://www.funcom.com
participants (3)
-
Geir B Hansen -
Jens Vagelpohl -
Martijn Faassen