Suggestion for a Python Extension
Cliff Crawford
cjc26 at nospam.cornell.edu
Thu Mar 23 19:34:43 EST 2000
* 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