TypeError

Bengt Richter bokr at accessone.com
Tue Aug 28 19:37:19 EDT 2001


On Tue, 28 Aug 2001 22:54:08 +0200, Martijn <martijn_500 at hotmail.com> wrote:

>Martijn wrote:
>
>> Hi,
>> 
>> I`ve got this error every time I want to use my classes and I can`t 
>> figure out what`s wrong. My code is ok and I`ve used some examples from 
>> a book to check it but I get the same error message.This is what happends:
>> 
>>  >>> import MyClassFile
>>  >>> m = MyClassFunction()
>> Traceback (innermost last)
>>         File "<stdin>"
>> TypeError: Call of nonfunction (type module)
>> 
>> I also tried:
>> 
>>  >>> import MyClassFile
>>  >>> m = MyClassFile.MyClassFunction()
>> 
>> And finaly :
>> 
>>  >>> from MyClassfile import *
>>  >>> m = MyClassFunction()
>> 
>> Both give me the same errors. What am i doing wrong ?!? I am using Linux 
>> btw.
>> 
>> 
>> Thanx in advance,
>> 
>> 
>> Martijn
>
>It still doesn`t work. This is a code snippet example from Python 2.1 Bible:
>
>class Wallet:
>	"where does my money go ?"
>		WalletCnt = 0
	WalletCnt = 0
>	def __init__(self,balance = 0):
>		self.balance = balance
>		Wallet.WalletCnt = Wallet.WalletCnt + 1
>	def getPaid(self,amnt):
>		self.balance = self.balance +1
>		self.display()
>
>	def spend(self,amnt):
>		self.balance = self.balance -1
>		self.display()
>	
>	def display:
        def display(self):
>		print 'New Balance: $%.2f; % self.balance
		print 'New Balance: $%.2f' % self.balance
>

if your class Wallet with above correction is in myClassFile.py
you should be able to do:
 >>> import MyClassFile
 >>> dir(MyClassFile)
 ['Wallet', '__builtins__', '__doc__', '__file__', '__name__']
 >>> aWallet = MyClassFile.Wallet(10)
 >>> dir(aWallet)
 ['balance']
 >>> dir(MyClassFile.Wallet)
 ['WalletCnt', '__doc__', '__init__', '__module__', 'display', 'getPaid', 'spend']
 >>> aWallet.display()
 New Balance: $10.00
 >>> aWallet.spend(3)
 New Balance: $9.00
 >>> aWallet.display()
 New Balance: $9.00
 >>> aWallet.spend(3.0)
 New Balance: $8.00
 >>> aWallet.WalletCnt
 1

I'll leave it to you to debug why you can only spend single dollars.
Something tells me you didn't do much homework before posting ;-)




More information about the Python-list mailing list