Re: Test string against expression?
Buck Golemon <[email protected]> Mon, 17 Sep 2012 11:57:38 -0700
| Newsgroups | gmane.comp.python.cheetah |
|---|---|
| Message-ID | <CANDQx1r5BvD_OEXRTAodj-do5s7Jb47f_K0OxMZLQQXZ720JNQ@mail.gmail.com> |
--===============7393914483362764084== Content-Type: multipart/alternative; boundary=0016e6da7ae1eaa09304c9ea5899 --0016e6da7ae1eaa09304c9ea5899 Content-Type: text/plain; charset=ISO-8859-1 If you're coming from Perl, the first thing you should know about python is that regular expressions are generally the Wrong Way to do it. Nearly everywhere you'd use a regex in perl, you use a string method in python. It's more explicit and faster (especially since regex in python is not super optimized like perl). On Mon, Sep 17, 2012 at 11:22 AM, Rick Miller <[email protected]>wrote: > On Mon, Sep 17, 2012 at 2:04 PM, Buck Golemon <[email protected]> wrote: > > Cheetah is a superset of python (kindof). > > Get your logic working in python, then port it to cheetah. > > You want re.match, from the standard python library: > > > > http://docs.python.org/library/re.html#re.RegexObject.match > > > > > > In your particular example below however, regular expressions are > overkill, > > just use the string `in` operator: > > > > #if 'string' in $getVar('name') > > #set foo = "bar" > > #else > > #set bar = "foo" > > #end if > > > > That's basic python. You should take a couple hours and run through the > > official tutorial. > > At *least* skim the parts on string processing. > > http://docs.python.org/tutorial/ > > Thanks, Buck! I'll check out that tutorial! > --0016e6da7ae1eaa09304c9ea5899 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable If you're coming from Perl, the first thing you should know about pytho= n is that regular expressions are generally the Wrong Way to do it.<div>Nea= rly everywhere you'd use a regex in perl, you use a string method in py= thon. It's more explicit and faster (especially since regex in python i= s not super optimized like perl).<br> <br><div class=3D"gmail_quote">On Mon, Sep 17, 2012 at 11:22 AM, Rick Mille= r <span dir=3D"ltr"><<a href=3D"mailto:[email protected]" target= =3D"_blank">[email protected]</a>></span> wrote:<br><blockquote c= lass=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;= padding-left:1ex"> <div class=3D"im">On Mon, Sep 17, 2012 at 2:04 PM, Buck Golemon <<a href= =3D"mailto:[email protected]">[email protected]</a>> wrote:<br> > Cheetah is a superset of python (kindof).<br> > Get your logic working in python, then port it to cheetah.<br> > You want re.match, from the standard python library:<br> ><br> > <a href=3D"http://docs.python.org/library/re.html#re.RegexObject.match= " target=3D"_blank">http://docs.python.org/library/re.html#re.RegexObject.m= atch</a><br> ><br> ><br> > In your particular example below however, regular expressions are over= kill,<br> > just use the string `in` operator:<br> ><br> > #if 'string' in $getVar('name')<br> > =A0 =A0#set foo =3D "bar"<br> > #else<br> > =A0 =A0#set bar =3D "foo"<br> > #end if<br> ><br> > That's basic python. You should take a couple hours and run throug= h the<br> > official tutorial.<br> > At *least* skim the parts on string processing.<br> > <a href=3D"http://docs.python.org/tutorial/" target=3D"_blank">http://= docs.python.org/tutorial/</a><br> <br> </div>Thanks, Buck! =A0I'll check out that tutorial!<br> </blockquote></div><br></div> --0016e6da7ae1eaa09304c9ea5899-- --===============7393914483362764084== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ --===============7393914483362764084== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Cheetahtemplate-discuss mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss --===============7393914483362764084==--