[BangPypers] problem with python classes
Abdul Muneer
abdulmuneer at gmail.com
Thu May 9 23:09:43 CEST 2013
Hi,
If it is necessary that the calculation has to be performed by ClassOne,
use a classmethod.
class ClassOne(object):
def __init__(self, value):
self.value = value
@classmethod
def calculate_value(cls, value):
<do something>
return new_value
and in ClassTwo, change the relevant line to this one.
self.values.append(ClassOne.calculate_value(inputvalues))
Regards,
Abdul Muneer
--
Follow me on Twitter: @abdulmuneer <http://twitter.com/#%21/abdulmuneer>
On Thu, May 9, 2013 at 9:11 PM, hiharry danny <hrdspl at gmail.com> wrote:
> i have python 2.7.4......now suppose i have two new-style base classes ,
> i.e. class ClassName(object):
> and the two base classes are related by __init__ constructor where the
> __init__ constructor of one base class is accessed by the __init property
> of the other base class , for example :
>
> class ClassOne(object):
> def __init__(self,value):
> self.value = value
>
> class ClassTwo(object):
> def __init__(self,inputvalues):
> self.values = []
> for i in inputvalues:
> self.values.append(ClassOne(inputvalues))
>
> if this be the case , then without using inheritance property of OOP ,i,e,
> without creating further new subclasses , how can I access other user
> defined methods of ClassOne class via Class Two class. The ouput value will
> be returned by a user defined method of ClassTwo but the computation will
> be done by a method of ClassOne which is called by the user defined method
> of class two ...?
>
> so what will be the solution ?
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> http://mail.python.org/mailman/listinfo/bangpypers
>
More information about the BangPypers
mailing list