Help with a utility class and having a method call another method from within
Ian
2ianbutt at rogers.com
Fri Sep 5 15:59:55 EDT 2003
I have written this utility class that has a method which calls
another method. I don't want to pass in the self parameter and was
wondering by doing this does it make the function to be private or
uncallable outside of the class.
This code below works, but I didn't really want to pass self into
testBob1(ideally having it as private), I wanted the declaration to be
def testBob1(a). Can someone explains to me why this can't be done ?
I would get the following error:
Traceback (most recent call last):
File "C:\Python22\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py",
line 301, in RunScript
exec codeObject in __main__.__dict__
File "X:\ibutt_1\EEU\development\prototype\martini\scripts\aaa.py",
line 3, in ?
print SampleClassd().testBob2(2)
File "SampleClass.py", line 15, in testBob2
return SampleClassd().testBob1(a)
TypeError: testBob1() takes exactly 1 argument (2 given
in file-->SampleClass.py
class SampleClassd :
def __init__(self) :
self.test = 'a'
def testBob1(self, a) :
if a == 1:
return True
else:
return False
def testBob2(self, a) :
return SampleClassd().testBob1(a)
Main file
=========
from SampleClass import SampleClassd
print SampleClassd().testBob2(2)
More information about the Python-list
mailing list