[Tutor] functions and errors

Terje Johan Abrahamsen terjeja@hotmail.com
Wed, 22 May 2002 15:33:21 +0000


I am trying to write a program that does several different tasks in Excel. 
However, before I get there, I have to understand the basics. This is what I 
have written so far.

import win32com.client
import win32com.client.dynamic
from win32com.client import Dispatch

class accountcurrents:
    #xlApp = Dispatch("Excel.Application")
    #ex = Dispatch("Extra.System")
    #xlApp.Visible = 1
    #xlApp.Workbooks.Add()
    #xlBook = xlApp.Workbooks(1)
    #xlSheet = xlApp.Sheets(1)

    def __init__(self):
        print"Hello"

    def finnxlpolicy():
        print"world"

The Excel part is just included so I can build further. But, my question is 
how can I get this to print world? If I type accountcurrents(), it prints 
Hello. If I try to write accountcurrents.finnxlpolicy() (stands for find 
policy in Excel, if you are curious) I get this error:

Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
TypeError: unbound method finnxlpolicy() must be called with accountcurrents 
instance as first argument (got nothing instead)

If I write n = accountcurrents(), n.finnxlpolicy() I get the following 
error:

Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
TypeError: finnxlpolicy() takes no arguments (1 given)

What do I do wrong? Thanks in advance....

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.