|
View:
New views
7 Messages
—
Rating Filter:
Alert me
|
|
|
Newbie question: non-escaping backslashes before placeholdersHi,
I'm new to Cheetah, and new to this list, I've got a question that I'm sure must have been asked before, but I can't find the answer in the documentation so I'm hoping somebody can help. I'm using Cheetah 2.2.1 / Python 2.5 under Windows to create some config files and I'm having problems creating windows paths. There's a cut-down example below. from Cheetah.Template import Template t = Template('#config_file "c:\$p1\$p2"') t.p1 = 'foo' t.p2 = 'bar' print t This outputs the following: #config_file "c:$p1$p2" What I really want is #config_file "c:\foo\bar" I can't figure out how to prevent the backslashes from escaping the following placeholder. I'm sure there's a simple answer. Thanks in advance. Jon Mills jonmills@... ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Cheetahtemplate-discuss mailing list Cheetahtemplate-discuss@... https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss |
|
|
Re: Newbie question: non-escaping backslashes before placeholdersOn Thu, 22 Oct 2009, Jon Mills wrote: > Hi, > > I'm new to Cheetah, and new to this list, > > I've got a question that I'm sure must have been asked before, but I > can't find the answer in the documentation so I'm hoping somebody can > help. > > I'm using Cheetah 2.2.1 / Python 2.5 under Windows to create some > config files and I'm having problems creating windows paths. > > There's a cut-down example below. > > from Cheetah.Template import Template > t = Template('#config_file "c:\$p1\$p2"') > t.p1 = 'foo' > t.p2 = 'bar' > print t "c:\${p1}\${p2}" Let me know if that doesn't work for you Cheers, -R. Tyler Ballance -------------------------------------- GitHub: http://github.com/rtyler Twitter: http://twitter.com/agentdero Blog: http://unethicalblogger.com ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Cheetahtemplate-discuss mailing list Cheetahtemplate-discuss@... https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss |
|
|
Re: Newbie question: non-escaping backslashes before placeholdersTyler,
Thanks for your quick response, unfortunately that doesn't seem to fix the problem. If I change my test code to: from Cheetah.Template import Template t = Template('#config_file "c:\${p1}\${p2}"') t.p1 = 'foo' t.p2 = 'bar' print t I get the following output: #config_file "c:${p1}${p2}" On Thu, Oct 22, 2009 at 8:00 AM, <tyler@...> wrote: > > On Thu, 22 Oct 2009, Jon Mills wrote: > >> Hi, >> >> I'm new to Cheetah, and new to this list, >> >> I've got a question that I'm sure must have been asked before, but I >> can't find the answer in the documentation so I'm hoping somebody can >> help. >> >> I'm using Cheetah 2.2.1 / Python 2.5 under Windows to create some >> config files and I'm having problems creating windows paths. >> >> There's a cut-down example below. >> >> from Cheetah.Template import Template >> t = Template('#config_file "c:\$p1\$p2"') >> t.p1 = 'foo' >> t.p2 = 'bar' >> print t > > If you wrap them in curly braces you should be fine, i.e. > > "c:\${p1}\${p2}" > > Let me know if that doesn't work for you > > Cheers, > -R. Tyler Ballance > -------------------------------------- > GitHub: http://github.com/rtyler > Twitter: http://twitter.com/agentdero > Blog: http://unethicalblogger.com > -- Jon Mills jonmills@... ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Cheetahtemplate-discuss mailing list Cheetahtemplate-discuss@... https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss |
|
|
Re: Newbie question: non-escaping backslashes before placeholdersOn Thu, 22 Oct 2009, Jon Mills wrote: > Tyler, > > Thanks for your quick response, unfortunately that doesn't seem to fix > the problem. > > If I change my test code to: > from Cheetah.Template import Template > t = Template('#config_file "c:\${p1}\${p2}"') > t.p1 = 'foo' > t.p2 = 'bar' > print t > > I get the following output: > #config_file "c:${p1}${p2}" Ah right, I'm daft, the backslash is escaping the dollarsign. I don't think there's a really good means of dealing with this sort of usecase to be honest, you could work around it for now by doing something like: #set cpath = "c:\\%s\\%s" % ($p1, $p2) \#config_file "$cpath" Less than ideal, I agree, but will at least get you going until I have time to dig into the compiler code Cheers, -R. Tyler Ballance -------------------------------------- GitHub: http://github.com/rtyler Twitter: http://twitter.com/agentdero Blog: http://unethicalblogger.com > On Thu, Oct 22, 2009 at 8:00 AM, <tyler@...> wrote: > > > > On Thu, 22 Oct 2009, Jon Mills wrote: > > > >> Hi, > >> > >> I'm new to Cheetah, and new to this list, > >> > >> I've got a question that I'm sure must have been asked before, but I > >> can't find the answer in the documentation so I'm hoping somebody can > >> help. > >> > >> I'm using Cheetah 2.2.1 / Python 2.5 under Windows to create some > >> config files and I'm having problems creating windows paths. > >> > >> There's a cut-down example below. > >> > >> from Cheetah.Template import Template > >> t = Template('#config_file "c:\$p1\$p2"') > >> t.p1 = 'foo' > >> t.p2 = 'bar' > >> print t > > > > If you wrap them in curly braces you should be fine, i.e. > > > > "c:\${p1}\${p2}" > > > > Let me know if that doesn't work for you ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Cheetahtemplate-discuss mailing list Cheetahtemplate-discuss@... https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss |
|
|
Re: Newbie question: non-escaping backslashes before placeholdersThanks Tyler, that works fine. It hadn't occurred to my that I could
use Python's string formatting as well as Cheetah's. Great support. Thanks again. On Thu, Oct 22, 2009 at 8:31 AM, <tyler@...> wrote: > > On Thu, 22 Oct 2009, Jon Mills wrote: > >> Tyler, >> >> Thanks for your quick response, unfortunately that doesn't seem to fix >> the problem. >> >> If I change my test code to: >> from Cheetah.Template import Template >> t = Template('#config_file "c:\${p1}\${p2}"') >> t.p1 = 'foo' >> t.p2 = 'bar' >> print t >> >> I get the following output: >> #config_file "c:${p1}${p2}" > > > Ah right, I'm daft, the backslash is escaping the dollarsign. > > I don't think there's a really good means of dealing with this sort of > usecase to be honest, you could work around it for now by doing > something like: > > #set cpath = "c:\\%s\\%s" % ($p1, $p2) > \#config_file "$cpath" > > Less than ideal, I agree, but will at least get you going until I > have time to dig into the compiler code > > > Cheers, > -R. Tyler Ballance > -------------------------------------- > GitHub: http://github.com/rtyler > Twitter: http://twitter.com/agentdero > Blog: http://unethicalblogger.com >> On Thu, Oct 22, 2009 at 8:00 AM, <tyler@...> wrote: >> > >> > On Thu, 22 Oct 2009, Jon Mills wrote: >> > >> >> Hi, >> >> >> >> I'm new to Cheetah, and new to this list, >> >> >> >> I've got a question that I'm sure must have been asked before, but I >> >> can't find the answer in the documentation so I'm hoping somebody can >> >> help. >> >> >> >> I'm using Cheetah 2.2.1 / Python 2.5 under Windows to create some >> >> config files and I'm having problems creating windows paths. >> >> >> >> There's a cut-down example below. >> >> >> >> from Cheetah.Template import Template >> >> t = Template('#config_file "c:\$p1\$p2"') >> >> t.p1 = 'foo' >> >> t.p2 = 'bar' >> >> print t >> > >> > If you wrap them in curly braces you should be fine, i.e. >> > >> > "c:\${p1}\${p2}" >> > >> > Let me know if that doesn't work for you > -- Jon Mills jonmills@... Sent from Stoke Gifford, South Gloucestershire, United Kingdom ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Cheetahtemplate-discuss mailing list Cheetahtemplate-discuss@... https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss |
|
|
Re: Newbie question: non-escaping backslashes before placeholdersOn Thu, Oct 22, 2009, Jon Mills wrote:
> > from Cheetah.Template import Template > t = Template('#config_file "c:\$p1\$p2"') t = Template('#config_file r"c:\$p1\$p2"') Note the 'r"' above -- I haven't tested that, though. It might need to be instead t = Template(r'#config_file "c:\$p1\$p2"') or even both t = Template(r'#config_file r"c:\$p1\$p2"') -- Aahz (aahz@...) <*> http://www.pythoncraft.com/ Member of the Groucho Marx Fan Club ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Cheetahtemplate-discuss mailing list Cheetahtemplate-discuss@... https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss |
|
|
Re: Newbie question: non-escaping backslashes before placeholdersI can't think of any 'pretty' way to do it, but here's another approach:
>>> print Template(r'''#config_file "$('c:\\%s\\%s'%($p1,$p2))"''', ... namespaces={'p1':'foo', 'p2':'bar'}) #config_file "c:\foo\bar" Template(r"#config_file $('\\%s\\%s'%($p1,$p2))") On Thu, 22 Oct 2009, Jon Mills wrote: > Thanks Tyler, that works fine. It hadn't occurred to my that I could > use Python's string formatting as well as Cheetah's. > > Great support. Thanks again. > > On Thu, Oct 22, 2009 at 8:31 AM, <tyler@...> wrote: >> >> On Thu, 22 Oct 2009, Jon Mills wrote: >> >>> Tyler, >>> >>> Thanks for your quick response, unfortunately that doesn't seem to fix >>> the problem. >>> >>> If I change my test code to: >>> from Cheetah.Template import Template >>> t = Template('#config_file "c:\${p1}\${p2}"') >>> t.p1 = 'foo' >>> t.p2 = 'bar' >>> print t >>> >>> I get the following output: >>> #config_file "c:${p1}${p2}" >> >> >> Ah right, I'm daft, the backslash is escaping the dollarsign. >> >> I don't think there's a really good means of dealing with this sort of >> usecase to be honest, you could work around it for now by doing >> something like: >> >> #set cpath = "c:\\%s\\%s" % ($p1, $p2) >> \#config_file "$cpath" >> >> Less than ideal, I agree, but will at least get you going until I >> have time to dig into the compiler code >> >> >> Cheers, >> -R. Tyler Ballance >> -------------------------------------- >> GitHub: http://github.com/rtyler >> Twitter: http://twitter.com/agentdero >> Blog: http://unethicalblogger.com >>> On Thu, Oct 22, 2009 at 8:00 AM, <tyler@...> wrote: >>>> >>>> On Thu, 22 Oct 2009, Jon Mills wrote: >>>> >>>>> Hi, >>>>> >>>>> I'm new to Cheetah, and new to this list, >>>>> >>>>> I've got a question that I'm sure must have been asked before, but I >>>>> can't find the answer in the documentation so I'm hoping somebody can >>>>> help. >>>>> >>>>> I'm using Cheetah 2.2.1 / Python 2.5 under Windows to create some >>>>> config files and I'm having problems creating windows paths. >>>>> >>>>> There's a cut-down example below. >>>>> >>>>> from Cheetah.Template import Template >>>>> t = Template('#config_file "c:\$p1\$p2"') >>>>> t.p1 = 'foo' >>>>> t.p2 = 'bar' >>>>> print t >>>> >>>> If you wrap them in curly braces you should be fine, i.e. >>>> >>>> "c:\${p1}\${p2}" >>>> >>>> Let me know if that doesn't work for you >> > > > > -- > Jon Mills > jonmills@... > Sent from Stoke Gifford, South Gloucestershire, United Kingdom > > ------------------------------------------------------------------------------ > Come build with us! The BlackBerry(R) Developer Conference in SF, CA > is the only developer event you need to attend this year. Jumpstart your > developing skills, take BlackBerry mobile applications to market and stay > ahead of the curve. Join us from November 9 - 12, 2009. Register now! > http://p.sf.net/sfu/devconference > _______________________________________________ > Cheetahtemplate-discuss mailing list > Cheetahtemplate-discuss@... > https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss > Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Cheetahtemplate-discuss mailing list Cheetahtemplate-discuss@... https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss |
| Free embeddable forum powered by Nabble | Forum Help |