Suggestion for a Python Extension

Luis Cortes lcortes at flash.net
Sat Mar 25 20:45:37 EST 2000


Thanks for the tip about __call__ I will revise my class!

What do you think about being able to extend/inherit from basic types
like lists and tuples??


On another subject, the reason I did not use None instead of Anonymous
is for the following situations:

What if you have a list like:

test = [ (None, 1), ( "tom", 2 ), ("joe", 3 ) ]

and for some reason you want to find all tuples that match None.  Which
brings me to my next question does
None match None?

Using my class I would hope you can do this

ptest = plist( test )

ans = ptest.query( None, Anonymous())


Although I am anxious to hear your comments, I will be gone to Zope
Training next week, so it will be awhile before I answer you, please let
me hear what you think though - I am interested!

Best Regards,
Luis.



Cliff Crawford wrote:

> * Luis Cortes menulis:
> | [snip]
> | I thought it might be nice to do the same with Python.  Except that
> | facts are really lists in Python.  For example:
> |
> | fact = [ (1,3), (2,3), (3,4)]
> | ans = fact( SomeAnonymousVariable, 3 )
> |
> | so that ans has:
> |
> | ans = [ (1,3), (2,3) ]
> |
> | I have create a couple of classes in Python to allow me to simulate
> | what I want, but it would be nice if it where built-in instead,
> | using my classes the last example would be:
> |
> | fact = plist( [ (1,3), (2,3), (3,4)] )
> | ans = fact.query( Anonymous(), 3 )
> |
> | so that ans has:
> |
> | ans = [ (1,3), (2,3) ]
> |
> | [other examples..]
>
> If all you want to is make the "query" method look like a function
> call, then you can simply rename it to be "__call__" instead.  For
> example:
>
> >>> class test:
> ...     def __call__(self):
> ...             print "Selamat datang!"
> ...
> >>> a=test()
> >>> a()
> Selamat datang!
>
> You would still need to create new instances of Anonymous() (or use
> None, as you suggest in the source) to indicate the variables,
> though.  But this isn't necessarily a bad thing; people already
> used to Python will have trouble understanding why
>
> ans = fact( SomeAnonymousVariable, 3 )
>
> doesn't raise a NameError.
>
> spend-less-time-on-syntax-and-more-on-semantics-<wink>-ly y'rs,
>
> --
> cliff crawford    -><-    http://www.people.cornell.edu/pages/cjc26/
>                                                        icq 68165166
> "IS I yes wardrobe yield [the] evaluation."     member of A.H.M.A.D.




More information about the Python-list mailing list