Re: overloading operators for a function object

2011-10-03 Thread Westley Martínez
On Fri, Sep 30, 2011 at 09:50:42PM -0700, Fletcher Johnson wrote: > Is it possible to overload operators for a function? > > For instance I would like to do something roughly like... > > def func_maker(): > def func(): pass > > def __eq__(other): > if other == "check": return True >

Re: overloading operators for a function object

2011-09-30 Thread Chris Rebert
On Fri, Sep 30, 2011 at 9:50 PM, Fletcher Johnson wrote: > Is it possible to overload operators for a function? > > For instance I would like to do something roughly like... > > def func_maker(): >  def func(): pass > >  def __eq__(other): >    if other == "check":  return True >    return False >

Re: Overloading Methods

2009-01-21 Thread "
Chris Rebert wrote: On Tue, Jan 20, 2009 at 10:18 AM, MRAB wrote: K-Dawg wrote: Can you overload methods in Python? Can I have multiple __inits__ with different parameters passed in? Simple answer: no. More complicated answer: Yes, with some caveats. You usually don't need to overload me

Re: Overloading Methods

2009-01-20 Thread TheFlyingDutchman
> > class Foo(object): > def __init__(self, a, b=10, c=None): > > Whereas in Java or C++ this would require several overloads, it can be > succinctly expressed as a single method in Python. > Not that it's important to the discussion, but, while Java does not have the capability to give defau

Re: Overloading Methods

2009-01-20 Thread Chris Rebert
(top-posting just for consistency) In that case, you might also be interested in: http://dirtsimple.org/2004/12/python-is-not-java.html Cheers, Chris On Tue, Jan 20, 2009 at 12:19 PM, K-Dawg wrote: > Thank you for the explanation. With my background in Java, I have to get > myself to think a l

Re: Overloading Methods

2009-01-20 Thread K-Dawg
Thank you for the explanation. With my background in Java, I have to get myself to think a little differently. Kevin On Tue, Jan 20, 2009 at 1:41 PM, Chris Rebert wrote: > On Tue, Jan 20, 2009 at 10:18 AM, MRAB wrote: > > K-Dawg wrote: > >> > >> Can you overload methods in Python? > >> > >> C

Re: Overloading Methods

2009-01-20 Thread Chris Rebert
On Tue, Jan 20, 2009 at 10:18 AM, MRAB wrote: > K-Dawg wrote: >> >> Can you overload methods in Python? >> >> Can I have multiple __inits__ with different parameters passed in? >> > Simple answer: no. More complicated answer: Yes, with some caveats. You usually don't need to overload methods in

Re: Overloading Methods

2009-01-20 Thread MRAB
K-Dawg wrote: Can you overload methods in Python? Can I have multiple __inits__ with different parameters passed in? Simple answer: no. -- http://mail.python.org/mailman/listinfo/python-list

Re: overloading for ladder logic

2008-11-07 Thread Aaron Brady
On Nov 7, 7:48 am, [EMAIL PROTECTED] wrote: > I am trying to simulate the execution of some PLC ladder logic in > python. > > I manually modified the rungs and executed this within python as a > proof of concept, but I'd like to be able to skip the  modification > step.  My thought was that this mi

Re: overloading for ladder logic

2008-11-07 Thread Benjamin Kaplan
On Fri, Nov 7, 2008 at 8:48 AM, <[EMAIL PROTECTED]> wrote: > I am trying to simulate the execution of some PLC ladder logic in > python. > > I manually modified the rungs and executed this within python as a > proof of concept, but I'd like to be able to skip the modification > step. My thought

Re: overloading for ladder logic

2008-11-07 Thread Paul McGuire
On Nov 7, 7:48 am, [EMAIL PROTECTED] wrote: > I am trying to simulate the execution of some PLC ladder logic in > python. > > I manually modified the rungs and executed this within python as a > proof of concept, but I'd like to be able to skip the  modification > step.  My thought was that this mi

Re: Overloading operators

2008-10-16 Thread Mr . SpOOn
On Thu, Oct 16, 2008 at 10:54 PM, Lie Ryan <[EMAIL PROTECTED]> wrote: > On Wed, 15 Oct 2008 14:34:14 +0200, Mr.SpOOn wrote: > Something that is more pythonic is something that doesn't use > multimethods. It's just an elaborated way to do type checking. In python, > you usually avoid type checking a

Re: Overloading operators

2008-10-16 Thread Lie Ryan
On Wed, 15 Oct 2008 14:34:14 +0200, Mr.SpOOn wrote: > Hi, > in a project I'm overloading a lot of comparison and arithmetic > operators to make them working with more complex classes that I defined. > > > What is the best way to do this? Shall I use a lot of "if...elif" > statements inside the ov

Re: Overloading operators

2008-10-16 Thread Mr . SpOOn
Thanks for the suggestion. I think I'm gonna try the multimethods way, that I didn't know about it. -- http://mail.python.org/mailman/listinfo/python-list

Re: Overloading operators

2008-10-15 Thread Kay Schluehr
On 15 Okt., 14:34, Mr.SpOOn <[EMAIL PROTECTED]> wrote: > Hi, > in a project I'm overloading a lot of comparison and arithmetic > operators to make them working with more complex classes that I > defined. > > Sometimes I need a different behavior of the operator depending on the > argument. For exam

Re: Overloading operators

2008-10-15 Thread Aaron "Castironpi" Brady
On Oct 15, 7:34 am, Mr.SpOOn <[EMAIL PROTECTED]> wrote: > Hi, > in a project I'm overloading a lot of comparison and arithmetic > operators to make them working with more complex classes that I > defined. > > Sometimes I need a different behavior of the operator depending on the > argument. For exa

Re: Overloading operators

2008-10-15 Thread Robert Lehmann
On Wed, 15 Oct 2008 14:34:14 +0200, Mr.SpOOn wrote: > Hi, > in a project I'm overloading a lot of comparison and arithmetic > operators to make them working with more complex classes that I defined. > > Sometimes I need a different behavior of the operator depending on the > argument. For example

Re: Overloading operators

2008-10-15 Thread Aaron "Castironpi" Brady
On Oct 15, 7:34 am, Mr.SpOOn <[EMAIL PROTECTED]> wrote: > Hi, > in a project I'm overloading a lot of comparison and arithmetic > operators to make them working with more complex classes that I > defined. > > Sometimes I need a different behavior of the operator depending on the > argument. For exa

Re: Overloading virtual method of widget without inheriting (PyQt)

2008-05-28 Thread Alex Gusarov
> I have a feeling that the form produced by Qt Designer, once converted to > code, contains references to QCalendarWidget where you really want to use a > customized calendar widget. If so, you should "promote" the calendar widget > in Qt Designer to use your widget instead, and make sure you impo

Re: Overloading virtual method of widget without inheriting (PyQt)

2008-05-27 Thread Francesco Bochicchio
On Tue, 27 May 2008 01:31:35 -0700, Alex Gusarov wrote: > Hello, I have strong .NET background with C# and want to do some > familiar things from it with Python, but don't know how. For example, > I created form in qt designer with QCalendarWidget, translated it into > Python module and want to ov

Re: Overloading __getitem__

2008-05-24 Thread Gabriel Genellina
En Thu, 22 May 2008 20:38:39 -0300, Andreas Matthias <[EMAIL PROTECTED]> escribió: > [EMAIL PROTECTED] wrote: > >> actually i ddin't think about the fact that you're overloading dict, which >> can already take multiple values in getitem > > Oh, I didn't know that. I totally misinterpreted the err

Re: Overloading __getitem__

2008-05-22 Thread inhahe
> Apparently, args already is a tuple, so this should be: > > def __getitem__(self, args): > > Is this documented somewhere? I couldn't find it anywhere. > Don't know, I just assumed it would take multiple arguments because I knew I had seen the form d[1,2] before, which incidentally is equival

Re: Overloading __getitem__

2008-05-22 Thread Andreas Matthias
[EMAIL PROTECTED] wrote: > actually i ddin't think about the fact that you're overloading dict, which > can already take multiple values in getitem Oh, I didn't know that. I totally misinterpreted the error message. > so how about > > class crazy: pass > > and then in your dict class: > > d

Re: Overloading __getitem__

2008-05-22 Thread inhahe
actually i ddin't think about the fact that you're overloading dict, which can already take multiple values in getitem so how about class crazy: pass and then in your dict class: def __getitem__(*args): if args[-1] is crazy: return self.get(args[:-1])*5 else: return self.get(args)

Re: Overloading __getitem__

2008-05-22 Thread inhahe
"inhahe" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > crazy = True > print foo['a',crazy] > just to clarify, you could use it like: crazy = "I'm crazy" #this only has to be done once print foo['a'] #not crazy print foo['a',crazy] #crazy (this may be totally unPythonic

Re: Overloading __getitem__

2008-05-22 Thread inhahe
it seems like you can't do it exactly the way you're trying but you could do this def __getitem__(*args): if len(args) > 1 and args[1]: return self.get(args[0]) * 5 return self.get(args[0]) then you would use it like print foo['a'] print foo['a',True] or even print foo['a',"crazy"] if you

Re: Overloading the tilde operator?

2007-02-08 Thread Markus Triska
[EMAIL PROTECTED] writes: > Also some flavours of Prolog, as descrived in the classic book by op/3 is part of the Prolog ISO standard: http://pauillac.inria.fr/~deransar/prolog/bips.html#operators so every compliant implementation has it. -- http://mail.python.org/mailman/listinfo/python-list

Re: Overloading the tilde operator?

2007-02-08 Thread gatti
On Feb 8, 7:02 am, Dave Benjamin <[EMAIL PROTECTED]> wrote: > Neil Cerutti wrote: > > There's been only one (or two?) languages in history that > > attempted to provide programmers with the ability to implement > > new infix operators, including defining precedence level and > > associativity (I ca

Re: Overloading the tilde operator?

2007-02-07 Thread greg
Dave Benjamin wrote: > Neil Cerutti wrote: > >> There's been only one (or two?) languages in history that >> attempted to provide programmers with the ability to implement >> new infix operators, including defining precedence level and >> associativity (I can't think of the name right now). > > Y

Re: Overloading the tilde operator?

2007-02-07 Thread Dave Benjamin
Neil Cerutti wrote: > There's been only one (or two?) languages in history that > attempted to provide programmers with the ability to implement > new infix operators, including defining precedence level and > associativity (I can't think of the name right now). You're probably thinking of SML or

Re: Overloading the tilde operator?

2007-02-02 Thread greg
James Stroud wrote: > You haven't addressed why the limitation isn't arbitrary. It's not arbitrary because there is a built-in meaning for infix minus, but not for infix tilde. Python doesn't go out of its way to provide operators which aren't used by at least one built-in type. -- Greg -- htt

Re: Overloading the tilde operator?

2007-02-02 Thread Neil Cerutti
On 2007-02-02, Ben Finney <[EMAIL PROTECTED]> wrote: > James Stroud <[EMAIL PROTECTED]> writes: >> Ben Finney wrote: >> > The Python runtime parser is designed to parse Python, not >> > some arbitrary language that someone chooses to implement in >> > Python. >> >> You haven't addressed why the lim

Re: Overloading the tilde operator?

2007-02-01 Thread Ben Finney
James Stroud <[EMAIL PROTECTED]> writes: > Ben Finney wrote: > > The Python runtime parser is designed to parse Python, not some > > arbitrary language that someone chooses to implement in Python. > > You haven't addressed why the limitation isn't arbitrary. Good thing I wasn't trying to do that,

Re: Overloading the tilde operator?

2007-02-01 Thread George Sakkis
On Feb 2, 12:49 am, James Stroud <[EMAIL PROTECTED]> wrote: > Ben Finney wrote: > > > The Python runtime parser is designed to parse Python, not some > > arbitrary language that someone chooses to implement in Python. > > You haven't addressed why the limitation isn't arbitrary. Indeed, and that'

Re: Overloading the tilde operator?

2007-02-01 Thread James Stroud
Ben Finney wrote: > James Stroud <[EMAIL PROTECTED]> writes: > > >>Peter Otten wrote: >> >>>Chris wrote: >>> I am trying to overload the __invert__ operator (~) such that it can take a second argument, >>> >>x ~ x >>> >>> File "", line 1 >>>x ~ x >>> ^ >>>SyntaxError: invali

Re: Overloading the tilde operator?

2007-02-01 Thread Ben Finney
James Stroud <[EMAIL PROTECTED]> writes: > Peter Otten wrote: > > Chris wrote: > >>I am trying to overload the __invert__ operator (~) such that it > >>can take a second argument, > > > x ~ x > > File "", line 1 > > x ~ x > > ^ > > SyntaxError: invalid syntax > > Seems an arbitrar

Re: Overloading the tilde operator?

2007-02-01 Thread James Stroud
Peter Otten wrote: > Chris wrote: > > >>I am trying to overload the __invert__ operator (~) such that >>it can take a second argument, other than >>self, so that I can express: >> >>x ~ y >> >>by using: >> >>def __invert__(self, other): >> >>for example. Is this possible? > > > No, you will ge

Re: Overloading the tilde operator?

2007-02-01 Thread bearophileHUGS
Peter Otten: > No, you will get a syntax error before python even look up the names: There are some tricks that allow the use of "undefined" symbols in Python too, but they are probably just toys. I have recently posted a recipe in the cookbook for that. Bye, bearophile -- http://mail.python.or

Re: Overloading the tilde operator?

2007-02-01 Thread Peter Otten
Chris wrote: > I am trying to overload the __invert__ operator (~) such that > it can take a second argument, other than > self, so that I can express: > > x ~ y > > by using: > > def __invert__(self, other): > > for example. Is this possible? No, you will get a syntax error before python ev

Re: Overloading assignment operator

2007-01-29 Thread Michael Spencer
J. Clifford Dyer wrote: > I think that's the first time I've actually seen someone use a Monty > Python theme for a python example, and I must say, I like it. However, > "We are all out of Wensleydale." > > Cheers, > Cliff Oh, then you clearly don't waste nearly enough time on this newsgroup ;

Re: Overloading assignment operator

2007-01-29 Thread J. Clifford Dyer
Steven D'Aprano wrote: > On Tue, 23 Jan 2007 18:07:55 -0800, Russ wrote: > >> Achim Domma wrote: >>> Hi, >>> >>> I want to use Python to script some formulas in my application. The user >>> should be able to write something like >>> >>> A = B * C >>> >>> where A,B,C are instances of some wrapper c

RE: Overloading assignment operator

2007-01-25 Thread Carroll, Barry
> -Original Message- > From: Gabriel Genellina [mailto:[EMAIL PROTECTED] > Sent: Tuesday, January 23, 2007 9:24 PM > To: python-list@python.org > Subject: Re: Overloading assignment operator > > "Carroll, Barry" <[EMAIL PROTECTED]> escribió

Re: Overloading assignment operator

2007-01-24 Thread John Pye
Hi thre, On Jan 24, 5:24 am, Achim Domma <[EMAIL PROTECTED]> wrote: > I want to use Python to script some formulas in my application. Depending on what you're trying to do, you might possibly find it useful to lake a look at the approach used by PyGINAC, which is a symbolic algebra system (in C++

Re: Overloading assignment operator

2007-01-23 Thread Steven D'Aprano
On Tue, 23 Jan 2007 18:07:55 -0800, Russ wrote: > Achim Domma wrote: >> Hi, >> >> I want to use Python to script some formulas in my application. The user >> should be able to write something like >> >> A = B * C >> >> where A,B,C are instances of some wrapper classes. Overloading * is no >> probl

Re: Overloading assignment operator

2007-01-23 Thread Gabriel Genellina
"Carroll, Barry" <[EMAIL PROTECTED]> escribió en el mensaje news:[EMAIL PROTECTED] > * ... the assignment operator is used to assign an > * object to a name in the current namespace... IOW, you cannot "overload > * the assignment operator." > (wesley chun) This is the key concept, if you want to

Re: Overloading assignment operator

2007-01-23 Thread Russ
Achim Domma wrote: > Hi, > > I want to use Python to script some formulas in my application. The user > should be able to write something like > > A = B * C > > where A,B,C are instances of some wrapper classes. Overloading * is no > problem but I cannot overload the assignment of A. I understand t

RE: Overloading assignment operator

2007-01-23 Thread Carroll, Barry
> -Original Message- > From: Achim Domma [mailto:[EMAIL PROTECTED] > Sent: Tuesday, January 23, 2007 10:25 AM > To: python-list@python.org > Subject: Overloading assignment operator > > Hi, > > I want to use Python to script some formulas in my application. The user > should be able to wr

Re: Overloading assignment operator

2007-01-23 Thread Peter Otten
Steven D'Aprano wrote: > On Tue, 23 Jan 2007 19:42:01 +0100, Peter Otten wrote: > >> Achim Domma wrote: >> >>> I want to use Python to script some formulas in my application. The user >>> should be able to write something like >>> >>> A = B * C >>> >>> where A,B,C are instances of some wrapper

Re: Overloading assignment operator

2007-01-23 Thread Achim Domma
Paul McGuire wrote: > Simple option: how do you feel about using '<<=' instead of '=' (by > defining __ilshift__)? This gives you: > > A <<= B * C > > (looks sort of like "injecting" the result of B times C into A) Thanks! That is exactly the kind of solution I was looking for! :-) Achim --

Re: Overloading assignment operator

2007-01-23 Thread Steven D'Aprano
On Tue, 23 Jan 2007 19:42:01 +0100, Peter Otten wrote: > Achim Domma wrote: > >> I want to use Python to script some formulas in my application. The user >> should be able to write something like >> >> A = B * C >> >> where A,B,C are instances of some wrapper classes. Overloading * is no >> pro

Re: Overloading assignment operator

2007-01-23 Thread Kay Schluehr
Achim Domma schrieb: > Hi, > > I want to use Python to script some formulas in my application. The user > should be able to write something like > > A = B * C > > where A,B,C are instances of some wrapper classes. Overloading * is no > problem but I cannot overload the assignment of A. I understa

Re: Overloading assignment operator

2007-01-23 Thread Erik Max Francis
Achim Domma wrote: > I want to use Python to script some formulas in my application. The user > should be able to write something like > > A = B * C > > where A,B,C are instances of some wrapper classes. Overloading * is no > problem but I cannot overload the assignment of A. I understand that

Re: Overloading assignment operator

2007-01-23 Thread Paul McGuire
On Jan 23, 12:24 pm, Achim Domma <[EMAIL PROTECTED]> wrote: > Hi, > > I want to use Python to script some formulas in my application. The user > should be able to write something like > > A = B * C > > where A,B,C are instances of some wrapper classes. Overloading * is no > problem but I cannot ove

Re: Overloading assignment operator

2007-01-23 Thread Peter Otten
Achim Domma wrote: > I want to use Python to script some formulas in my application. The user > should be able to write something like > > A = B * C > > where A,B,C are instances of some wrapper classes. Overloading * is no > problem but I cannot overload the assignment of A. I understand that >

Re: Overloading "if object" unary operator

2006-11-29 Thread Fredrik Lundh
Sarcastic Zombie wrote: > If I have a class > > class A: > __init__(id) > self.id = id > > is there any way to overload the 'if' unary usage to detect if a > variable has a value? http://effbot.org/pyref/__nonzero__ -- http://mail.python.org/mailman/listinfo/python-list

Re: Overloading "if object" unary operator

2006-11-29 Thread Sarcastic Zombie
On Nov 29, 11:26 am, Peter Otten <[EMAIL PROTECTED]> wrote: > Sarcastic Zombie wrote: > > is there any way to overload the 'if' unary usage to detect if a > > variable has a value?Define a __nonzero__() or __len__() method. > > Peter Thanks to both of you, it worked perfectly. I must have missed

Re: Overloading "if object" unary operator

2006-11-29 Thread Peter Otten
Sarcastic Zombie wrote: > is there any way to overload the 'if' unary usage to detect if a > variable has a value? Define a __nonzero__() or __len__() method. Peter -- http://mail.python.org/mailman/listinfo/python-list

Re: Overloading "if object" unary operator

2006-11-29 Thread Roberto Bonvallet
Sarcastic Zombie wrote: > For example, in the code: > > a = A(56) > if a: >print "Hoo hah!" > > how can I insure that the if will come back true and fire off the print > if and only if self.id is defined? I want to do this in an overloaded, > generic way, if possible; I know that I could test

Re: overloading constructor in python?

2006-04-03 Thread Jon Ribbens
In article <[EMAIL PROTECTED]>, Alex Martelli wrote: >> I guess in python we use two idioms to cover most of the uses of >> mulltiple constructors: > > ... and classmethods. OK, _three_ idioms. Oh, and factory functions. > Among the idioms we use are the following... Nobody expects the Spanglis

Re: overloading constructor in python?

2006-04-03 Thread Alex Martelli
Paddy <[EMAIL PROTECTED]> wrote: > I guess in python we use two idioms to cover most of the uses of > mulltiple constructors: > 1) Duck typing were for example if you do: > > class C1(object): > def __init__(self, n): > n = float(n) > > n could be an integer, a floating point number,, or

Re: overloading constructor in python?

2006-04-03 Thread Paddy
I guess in python we use two idioms to cover most of the uses of mulltiple constructors: 1) Duck typing were for example if you do: class C1(object): def __init__(self, n): n = float(n) n could be an integer, a floating point number,, or a string representing a float. 2) Default values to

Re: overloading constructor in python?

2006-04-03 Thread Jarek Zgoda
Larry Bates napisał(a): > In python it is called duck typing but you don't need separate > constructors: > > def __init__(self, c): > if isinstance(c, int): ...do stuff... > elif isinstance(c, list): ...do stuff... > elif isinstance(c, tuple): ...do stuff... > else: > . >

Re: overloading constructor in python?

2006-04-03 Thread lennart
Larry Bates wrote: [...] > In python it is called duck typing but you don't need separate > constructors: > > def __init__(self, c): > if isinstance(c, int): ...do stuff... > elif isinstance(c, list): ...do stuff... > elif isinstance(c, tuple): ...do stuff... > else: > . >

Re: overloading constructor in python?

2006-04-03 Thread Larry Bates
[EMAIL PROTECTED] wrote: > This is probably a really stupid question, but I cant seem to find a > satisfying answer by myself so here it goes. In for example java we > could create a class dummie with several constructors, say one that > takes an int, and one that takes a String as argument. In pyt

Re: Overloading

2005-12-09 Thread Josef Meile
>>> In C++ you can overload functions and constructors. For example if I >>> have a >>> class that represents a complex number, than it would be nice if I can >>> write two seperate constructors >> >> >> >> Python doesn't support this, but it does support default arguments: > > Yes, in part you a

Re: Overloading

2005-12-09 Thread Josef Meile
>>In C++ you can overload functions and constructors. For example if I have a >>class that represents a complex number, than it would be nice if I can >>write two seperate constructors > > > Python doesn't support this, but it does support default arguments: Yes, in part you are right since the p

Re: Overloading

2005-12-09 Thread Christopher Subich
Johannes Reichel wrote: > Hi! > > In C++ you can overload functions and constructors. For example if I have a > class that represents a complex number, than it would be nice if I can > write two seperate constructors > > class Complex: Please do note, if you want this for the exact use of a Comp

Re: Overloading

2005-12-09 Thread jepler
On Fri, Dec 09, 2005 at 06:29:12PM +0100, Johannes Reichel wrote: > Hi! > > In C++ you can overload functions and constructors. For example if I have a > class that represents a complex number, than it would be nice if I can > write two seperate constructors Python doesn't support this, but it do

Re: Overloading

2005-12-09 Thread Jean-Paul Calderone
On Fri, 09 Dec 2005 18:29:12 +0100, Johannes Reichel <[EMAIL PROTECTED]> wrote: >Hi! > >In C++ you can overload functions and constructors. For example if I have a >class that represents a complex number, than it would be nice if I can >write two seperate constructors > >class Complex: > >def __ini

Re: overloading *something

2005-11-09 Thread Robert Kern
James Stroud wrote: > That **kwargs insists on using the C-side interface is precisely the > annoyance > to which I am referring. I should be able to write a dictionary-like > interface in python and **kwargs should in turn be able to use it. If the > retort is that the C-side interface is use

Re: overloading *something

2005-11-09 Thread [EMAIL PROTECTED]
Robert Kern wrote: > James Stroud wrote: > > > Does anyone else find the following annoying: > > > > py> from UserDict import UserDict > > py> aud = UserDict({"a":1, "b":2}) > > py> def doit(**kwargs): > > ... print kwargs > > UserDict only exists for backwards compatibility with old code that us

Re: overloading *something

2005-11-09 Thread James Stroud
On Tuesday 08 November 2005 22:54, Robert Kern wrote: > James Stroud wrote: > > Does anyone else find the following annoying: > > > > py> from UserDict import UserDict > > py> aud = UserDict({"a":1, "b":2}) > > py> def doit(**kwargs): > > ... print kwargs > > ... > > py> aud > > {'a': 1, 'b': 2}

Re: overloading *something

2005-11-08 Thread Robert Kern
James Stroud wrote: > Does anyone else find the following annoying: > > py> from UserDict import UserDict > py> aud = UserDict({"a":1, "b":2}) > py> def doit(**kwargs): > ... print kwargs > ... > py> aud > {'a': 1, 'b': 2} > py> doit(**aud) > Traceback (most recent call last): > File "", line

Re: overloading *something

2005-11-08 Thread James Stroud
On Monday 07 November 2005 20:36, Alex Martelli wrote: > Ron Adam <[EMAIL PROTECTED]> wrote: > > James Stroud wrote: > > > Hello All, > > > > > > How does one make an arbitrary class (e.g. class myclass(object)) > > > behave like a list in method calls with the "*something" operator? What > > > I m

Re: overloading *something

2005-11-08 Thread Peter Otten
James Stroud wrote: > I was attempting to re-define iter of a subclassed list, to find the > "magic" method, but it didn't work. >>> class List(list): ... def __iter__(self): return iter("abc") ... >>> a = List([1,2,3]) >>> list(a) ['a', 'b', 'c'] >>> tuple(a) (1, 2, 3) list-to-tuple conver

Re: overloading *something

2005-11-08 Thread Bengt Richter
On Mon, 7 Nov 2005 20:39:46 -0800, James Stroud <[EMAIL PROTECTED]> wrote: >On Monday 07 November 2005 20:21, Robert Kern wrote: >> James Stroud wrote: >> > Hello All, >> > >> > How does one make an arbitrary class (e.g. class myclass(object)) behave >> > like a list in method calls with the "*som

Re: overloading *something

2005-11-07 Thread Ron Adam
Alex Martelli wrote: > Ron Adam <[EMAIL PROTECTED]> wrote: > > >>James Stroud wrote: >>>And, how about the "**something" operator? >>> >>>James >> >>A dictionary would be pretty much the same except subclassed from a >>dictionary of course. > > > I believe this one is correct (but I have no

Re: overloading *something

2005-11-07 Thread James Stroud
On Monday 07 November 2005 20:36, Alex Martelli wrote: > > > I've looked at getitem, getslice, and iter. What is it if not one of > > > these? > > Obviously James hadn't looked at __iter__ in the RIGHT way! I was attempting to re-define iter of a subclassed list, to find the "magic" method, but i

Re: overloading *something

2005-11-07 Thread Leif K-Brooks
James Stroud wrote: > Hello All, > > How does one make an arbitrary class (e.g. class myclass(object)) behave like > a list in method calls with the "*something" operator? What I mean is: > > myobj = myclass() > > doit(*myobj) Make it iterable: >>> class Foo(object): ... def __iter__(se

Re: overloading *something

2005-11-07 Thread Alex Martelli
Ron Adam <[EMAIL PROTECTED]> wrote: > James Stroud wrote: > > > Hello All, > > > > How does one make an arbitrary class (e.g. class myclass(object)) behave > > like a list in method calls with the "*something" operator? What I mean > > is: > > You need to base myclass on a list if I understand

Re: overloading *something

2005-11-07 Thread James Stroud
On Monday 07 November 2005 20:21, Robert Kern wrote: > James Stroud wrote: > > Hello All, > > > > How does one make an arbitrary class (e.g. class myclass(object)) behave > > like a list in method calls with the "*something" operator? What I mean > > is: > > > > myobj = myclass() > > > > doit(*myob

Re: overloading *something

2005-11-07 Thread Ron Adam
James Stroud wrote: > Hello All, > > How does one make an arbitrary class (e.g. class myclass(object)) behave like > a list in method calls with the "*something" operator? What I mean is: You need to base myclass on a list if I understand your question. class myclass(list): def __init__

Re: overloading *something

2005-11-07 Thread Robert Kern
James Stroud wrote: > Hello All, > > How does one make an arbitrary class (e.g. class myclass(object)) behave like > a list in method calls with the "*something" operator? What I mean is: > > myobj = myclass() > > doit(*myobj) > > I've looked at getitem, getslice, and iter. What is it if not o

Re: Overloading & Overriden

2005-10-15 Thread Scott David Daniels
Fredrik Lundh wrote: > "Iyer, Prasad C" wrote: >>...This message contains information that may be privileged or confidential >>and is the property of the Capgemini Group. It is intended only for the >>person to whom it is addressed. If you are not the intended recipient, >>you are not authorized

Re: Overloading __init__ & Function overloading

2005-09-30 Thread John J. Lee
Paul Rubin <"http://phr.cx"@NOSPAM.invalid> writes: > "Iyer, Prasad C" <[EMAIL PROTECTED]> writes: > > But I want to do something like this > > > > class BaseClass: > > def __init__(self): > > # Some code over here > > def __init__(self, a, b): > > # Some code over

Re: Overloading __init__ & Function overloading

2005-09-30 Thread Fredrik Lundh
"Iyer, Prasad C" wrote: > Thanks a lot for the reply. > But I want to do something like this > > class BaseClass: > def __init__(self): > # Some code over here > def __init__(self, a, b): > # Some code over here > def __init__(self, a, b, c): > # some code here did you read the FAQ I pointed you

Re: Overloading __init__ & Function overloading

2005-09-30 Thread Christopher Subich
Iyer, Prasad C wrote: > Thanks a lot for the reply. > But I want to do something like this > > class BaseClass: > def __init__(self): > # Some code over here > def __init__(self, a, b): > # Some code over here > def __init__(self, a, b, c): >

Re: Overloading __init__ & Function overloading

2005-09-30 Thread Istvan Albert
in python you can provide default values for your parameters: class BaseClass: def __init__(self, a=None): if a is None: #no parameter pass else: #one parameter pass baseclass1=BaseClass() baseclass2=BaseClass(1) --

Re: Overloading __init__ & Function overloading

2005-09-30 Thread Fredrik Lundh
Larry Bates wrote: >I may be reading this question different than Fredrik. it looks like you're using a non-standard definition of the word "overloading". here are the usual definitions (quoting from a random google page): "Overloading a method refers to having two methods which share the

Re: Overloading __init__ & Function overloading

2005-09-30 Thread Paul Rubin
"Iyer, Prasad C" <[EMAIL PROTECTED]> writes: > But I want to do something like this > > class BaseClass: > def __init__(self): > # Some code over here > def __init__(self, a, b): > # Some code over here > def __init__(self, a, b, c): > #

RE: Overloading __init__ & Function overloading

2005-09-30 Thread Iyer, Prasad C
baseclass1=BaseClass() baseclass2=BaseClass(2,3) baseclass3=BaseClass(4,5,3) regards prasad chandrasekaran --- Cancer cures smoking -Original Message- From: Larry Bates [mailto:[EMAIL PROTECTED] Sent: Friday, September 30, 2005 7:39 PM To: Iyer, Prasad C Subject: Re: Overloading

Re: Overloading & Overriden

2005-09-30 Thread Fredrik Lundh
"Iyer, Prasad C" wrote: > Does python supports Overloading & Overriding of the function? Please avoid posting the same question over and over again with different subjects. Please read the replies to your original question before reposting the question. This is a mail list, not a chat channel;

Re: Overloading __init__ & Function overloading

2005-09-30 Thread Michael Hoffman
Larry Bates wrote: > class myclass(baseclass): > def __init__(self, arg): > # > # This method gets called when I instantiate this class. > # If I want to call the baseclass.__init__ method I must > # do it myself. > # > baseclass.__init__(arg) T

Re: Overloading __init__ & Function overloading

2005-09-30 Thread Larry Bates
I may be reading this question different than Fredrik. This example is with old-style classes. class baseclass: def __init__(self, arg): # # Do some initialization # def method1(self, arg): # # baseclass method goes here # class myclass(ba

Re: Overloading __init__ & Function overloading

2005-09-30 Thread Steve Holden
Iyer, Prasad C wrote: > I am new to python. > I have few questions > a. Is there something like function overloading in python? Not in the same way as Java: you can't write several functions and have the compiler or run-rime system work out which one to call according to argument types. Don't fo

Re: Overloading __init__ & Function overloading

2005-09-30 Thread Fredrik Lundh
"Iyer, Prasad C" wrote: > a. Is there something like function overloading in python? not in the usual sense, no. function arguments are not typed, so there's nothing to dispatch on. there are several cute tricks you can use to add dispatching on top of "raw" python, but that's nothing you shou

Re: Overloading the "and" operator

2005-03-13 Thread Terry Reedy
"Fredrik Bertilsson" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >I am trying to overload the "and" operatior, but my __and__ method is > never called. That is because, properly speaking, 'and' and 'or' are, in Python, in-line flow-control keywords (related to 'if' and 'else'),

Re: Overloading the "and" operator

2005-03-12 Thread Robert Kern
Fredrik Bertilsson wrote: I am trying to overload the "and" operatior, but my __and__ method is never called. __and__ overloads the "&" operator. The "and" keyword cannot be overloaded. -- Robert Kern [EMAIL PROTECTED] "In the fields of hell where the grass grows high Are the graves of dreams allo

Re: Overloading ctor doesn't work?

2005-01-21 Thread Kent Johnson
Nick Craig-Wood wrote: Martin Häcker <[EMAIL PROTECTED]> wrote: Now I thought, just overide the ctor of datetime so that year, month and day are static and everything should work as far as I need it. That is, it could work - though I seem to be unable to overide the ctor. :( Its a bug! http:

Re: Overloading ctor doesn't work?

2005-01-21 Thread Nick Craig-Wood
Martin Häcker <[EMAIL PROTECTED]> wrote: > Now I thought, just overide the ctor of datetime so that year, month and >day are static and everything should work as far as I need it. > > That is, it could work - though I seem to be unable to overide the ctor. :( > > Why is that? Its a bug!

  1   2   >