"Paul McGuire" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> See the following.
> -- Paul
>
> class X(object):
> pass
>
> def makeAddr(tAdd):
> def add(self, tNum):
> return tNum + tAdd
> return add
>
> # add methods to class X
> X.add1 = makeAddr(1)
> X.add100
Thanks that made it work. If I did it that way I think the other
programmers on my team would kill me so I will stick with wrapping the
function over and over again.
--
http://mail.python.org/mailman/listinfo/python-list
Thanks I will try that.
--
http://mail.python.org/mailman/listinfo/python-list
See the following.
-- Paul
class X(object):
pass
def makeAddr(tAdd):
def add(self, tNum):
return tNum + tAdd
return add
# add methods to class X
X.add1 = makeAddr(1)
X.add100 = makeAddr(100)
# create an X object
x = X()
# invoke new methods
print x.add1( 50 )
print x.add100
Also note I can't read or type is seems.
what I want to know is how to take a function like.
I realley need to fininsh my coke before I try to think.
--
http://mail.python.org/mailman/listinfo/python-list
What I wanted it to know how to. Take a function like.
Note replace ... with spaces.
def makeAddr(tAdd):
def add(tNum):
return tNum + tAdd
return add
In a class so I make several functions that do the same thing but on
diffrent objects.
I ended up writing a base function and just
Well, despite my parenthetical disclaimer, my attempted point was that
the OP wanted to avoid replicating several functions that were mostly
the same. I think Python's idiom of using a function to create and
return callables is a comparable feature to using anonymous closures.
Unfortunately, I gue
<[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>I have several functions that are almost the same in one class I would
> like to use a closure to get rid of the extra code how would I do this?
A more specific example might get a more to the point solution ;-)
TJR
--
http://mail
In article <[EMAIL PROTECTED]>,
Paul McGuire <[EMAIL PROTECTED]> wrote:
>Well, I'm not sure "closure" is the Pythonic way. But in Python, you
>can use functions to dynamically create other functions. Here's an
>example of this feature (although there are far simpler ways to do
>this), tallying vo
Well, I'm not sure "closure" is the Pythonic way. But in Python, you
can use functions to dynamically create other functions. Here's an
example of this feature (although there are far simpler ways to do
this), tallying vowels and consonants in an input string by calling a
function looked up in a
I have several functions that are almost the same in one class I would
like to use a closure to get rid of the extra code how would I do this?
--
http://mail.python.org/mailman/listinfo/python-list
11 matches
Mail list logo