[NEWBIE]-Object referencing??

Max M maxm at mxm.dk
Tue Jul 2 02:03:02 EDT 2002


Alistair Campbell wrote:

> I assign data from a file so the data that goes into the alcohol method
> needs to be converted from string.


You should probably use int() then::

      def alcohol(self):
          return 
((int(self.hydro_init)-int(self.hydro_final))*0.00036251)*10


> The problem is that when I try to reference an instantiation of the Brew()
> class, i.e;
> 
> current_brew=Brew()
> 
> I can get all the other data items but a call to;
> 
> current_brew.alcohol
> 
> returns
> 
> <bound method Brew.alcohol of <__main__.Brew instance at 0x01761250>


This is because you do not call the method, but you just reference it.

To call it you need to add perenthesis::

     current_brew.alcohol()

Unlike VB you must state explicitly that you want to call a 
function/method. You can pass a funcion like any other object in Python.

You could even do::

get_alcohol = current_brew.alcohol
get_alcohol()


regards Max M




More information about the Python-list mailing list