Jan Strube (el 2007-02-28 a les 14:49:05 -0800) va dir::

> […]
> For combined in-kernel searches .where('x<5 & x>3'), I don't think & is a
> good choice.
> The Pythonic way would be 'and', and I think that's least ambiguous and I
> hope nobody names their variables 'and' or 'or.
> Maybe && would be OK, since that's used in other languages.
> Also, is something like '3<x<4' going to be supported as well ?
> […]

Glad to hear that you appreciate our work, thank you!

Regarding search expressions, they are in fact Python expressions
written as strings, and they are evaluated as such.  This has the
advantage of not having to learn a new syntax, but it also implies some
limitations with logical ``and`` and ``or`` operators, namely that they
can not be overloaded in Python.  Thus, it is impossible right now to
get an element-wise operation out of an expression like ``array1 and
array2``.  That's why one has to choose some other operator, being ``&``
and ``|`` the most similar to their C counterparts ``&&`` and ``||``,
which aren't available in Python either.

The problematic part is that operator precedence is quite different
between bitwise and logical operators, so ``x<5 & x>3`` is in fact
equivalent to ``(x < (5 & x)) > 3``, not ``(x < 5) & (x > 3)``.  A
seasoned Python programmer should not fall in the trap, but for others
we hope to have been quite clear in the appendix about condition syntax
in the manual.

The expression ``3<x<4`` is affected by the same limitation, since it is
treated by Python as ``(3 < x) and (x < 4)``.

There are quite a few packages affected by this limitation including
Numeric/numarray/NumPy and SQLObject, and there have been quite longish
discussions about adding the possibility of overloading boolean
operators to Python (see PEP 335 and the neverending thread
http://mail.python.org/pipermail/python-dev/2004-September/048763.html).

However, if you can think of a solution which doesn't imply creating a
whole parser for expressions, it would be really great!

::

        Ivan Vilata i Balaguer   >qo<   http://www.carabos.com/
               Cárabos Coop. V.  V  V   Enjoy Data
                                  ""

Attachment: signature.asc
Description: Digital signature

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Pytables-users mailing list
Pytables-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pytables-users

Reply via email to