[stringtemplate-interest] Problem in multivalued attribute
handling?
Praki Prakash
praki.prakash at gmail.com
Sat Jul 8 18:27:16 PDT 2006
Terence,
Thanks for the response. Allow me to say that your String Template design is
excellent and I hope it catches on. As someone who has had to fix a
ColdFusion based application with absolutely no concept of model-view and
their separation, I can see how a well-defined template engine can prevent
monstrosities being created. StringTemplate is certainly a good example of
less being more!
As far as my problem, Python's definition of True/False is below:
In the context of Boolean operations, and also when expressions are used by
control flow statements, the following values are interpreted as false:
False, None, numeric zero of all types, and empty strings and containers
(including strings, tuples, lists, dictionaries, sets and frozensets). All
other values are interpreted as true.
The Pythonic way to explicitly check for non-existent values is "if x is
None:". My quick glance at the Python code seemed to contain "if x:".
Thanks,
Praki
On 7/8/06, Terence Parr <parrt at cs.usfca.edu> wrote:
>
>
> On Jul 8, 2006, at 12:11 PM, Praki Prakash wrote:
>
> > Hi Colin,
> >
> > Thanks for your response.
> >
> > I suspect as much that the code is written as "if attr:" which
> > would cause all numerical zeros to evaluate to false.
>
> Could it be that Python treats 0 as false for some reason? Python
> has booleans, right?
>
> 0 is not missing by definition; so must be a Python bug that's
> all...I'm cc'ing Python guy Marq.
>
> Ter
>
>
> > From my perspective, this is a terrible bug making ST completely
> > unusable. My model is full of multi-dimensional data and quite a
> > bit of it is 0. Unfortunately, the workaround you suggest is not
> > really usable as I need numerical data to do computations and
> > having to generate a stringified version is too much work and
> > inelegant.
> >
> > I tried to hack the code a bit. I found a method,
> > convertAnythingToList and tried to alter the way it checks
> > attributes. My intuition proved to be wrong and it didn't fix the
> > issue. I suspect there is more code elsewhere that needs change.
> > Unfortunately, I don't have time to look into this and have had to
> > suspend the use of StringTemplate in project for now. If you come
> > up with patches, please post :)
> >
> > Thanks,
> > Praki
> >
> > On 7/7/06, Colin Bean <ccbean at gmail.com> wrote: Hi Praki,
> >
> > I noticed a similar issue recently; I hadn't gotten around to looking
> > at it in depth (I also hadn't verified it in 2.2 yet, but sounds like
> > its still there). As far as I know, PyST won't render any attribute
> > (that's passed as an int or float) with a value of zero. I haven't
> > looked at the source code, but I assume that somewhere there's a
> > conditional that checks for the value/existence of an attribute, then
> > checks it in such a way that a 0 evaluates to false and ST doesn't
> > think that the attribute exists. If you're passing integer values
> > into a template, casting them to a string before passing them causes
> > all zero values to render correctly (that's the workaround I've been
> > using for now, anyway).
> >
> > So I haven't verified if this is expected behavior or if this is
> > unique to the python implementation, but I've noticed the same
> > behavior. I'm on vacation this weekend, so I don't have any ST code
> > near at hand, but when I get back I'll verify the above assumptions
> > and report back ;)
> >
> > Anyone else? Is this a feature or a bug?
> >
> > Thanks,
> > -Colin
> >
> > On 7/6/06, Praki Prakash <praki.prakash at gmail.com> wrote:
> > > Hi,
> > >
> > > While using the Python version of StringTemplate, I noticed that my
> > > multivalued attribute was missing all the zero values. The
> > following snippet
> > > demonstrates the problem. I am using version 2.2. Is this a bug?
> > Is there a
> > > workaround?
> > >
> > > >>> import stringtemplate
> > > >>> st=stringtemplate.StringTemplate("$[0,1,0,1]:{$it$}$")
> > > >>> print st
> > > 11
> > >
> > > Thanks
> > > Praki
> > > _______________________________________________
> > > stringtemplate-interest mailing list
> > > stringtemplate-interest at antlr.org
> > > http://www.antlr.org:8080/mailman/listinfo/stringtemplate-interest
> > >
> > >
> > >
> >
> > _______________________________________________
> > stringtemplate-interest mailing list
> > stringtemplate-interest at antlr.org
> > http://www.antlr.org:8080/mailman/listinfo/stringtemplate-interest
>
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org:8080/mailman/listinfo/stringtemplate-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org:8080/pipermail/stringtemplate-interest/attachments/20060708/2c75b649/attachment.html
More information about the stringtemplate-interest
mailing list