From: Francesc A. <fa...@py...> - 2004-09-16 16:48:14
|
Dear PyTables users, I'm pondering to disable most of __call__() methods is PyTables objects because of two things: 1.- ipython (http://ipython.scipy.org/), which is a very good shell for Python adds by default the parenthesis '()' if you type just a name at the prompt and nothing more. Example: In [7]: float ------> float() Out[7]: 0.0 This is considered a good thing for most uses. Unfortunately, PyTables is designed to make use of bare object names to print a description of the object. That is, in the standard python console: >>> f.root.small /small (Group) 'small Group' children := ['create_worst' (Table), 'search_best' (Group), 'search_worst' (Group), 'create_best' (Table)] but the same in ipython gives: In [9]: f.root.small ------> f.root.small() Out[9]: <generator object at 0x415d490c> which is not was the user intended usually. 2.- More importantly, in my struggle to make interactive work with pytables easy, I'm afraid that I've abused a bit of the __call__ method, in most cases being introduced as a shortcut basically. For example, this is a typical use: >>> names=[ x['name'] for x in table(start=2, stop=1000) if x['TDCcount']>3] which is the same as: >>> names=[ x['name'] for x in table.iterrows(start=2, stop=1000) if x['TDCcount']>3] As I see it now, I find the second version much more clear, and although it is a bit more expensive to type, if we follow the mantra "explicit is better than implicit" I definitely think that the second is the way to go. So, these are the reasons why I'm planning to remove most of the __call__() methods and, if necessary, replace them by acurate method names. Although I think this is a good thing (TM), this may pose problems of backward compatibility with existing programs, and this is why I'm asking here. What do you think? You would like the change? That might cause problems with your programs? Do you have a better alternative? Cheers, -- Francesc Alted |