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
>
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
>
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
>
> 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
(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
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
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
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
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
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
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
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
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
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
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
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
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
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
> 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
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
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
> 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
[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
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)
"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
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
[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
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
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
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
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
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
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,
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'
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
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
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
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
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
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 ;
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
> -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ó
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++
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
"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
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
> -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
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
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
--
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
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
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
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
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
>
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
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
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
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
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
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
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
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:
> .
>
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:
> .
>
[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
>>> 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
>>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
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
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
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
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
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
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}
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
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
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
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
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
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
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
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
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
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__
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
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
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
"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
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):
>
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)
--
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
"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):
> #
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
"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;
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
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
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
"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
"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'),
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
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:
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 - 100 of 107 matches
Mail list logo