TypeError

Ignacio Vazquez-Abrams ignacio at openservices.net
Tue Aug 28 23:23:13 CEST 2001


On Tue, 28 Aug 2001, Martijn wrote:

> Martijn wrote:
> 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
> 	def __init__(self,balance = 0):
> 		self.balance = balance
> 		Wallet.WalletCnt = Wallet.WalletCnt + 1
> 	def getPaid(self,amnt):
> 		self.balance = self.balance +1
                                             ^

Shouldn't this be amnt instead?

> 		self.display()
>
> 	def spend(self,amnt):
> 		self.balance = self.balance -1
                                             ^

As above.

> 		self.display()
>
> 	def display:
                   ^

Whoops. Try 'def display():' instead.

> 		print 'New Balance: $%.2f; % self.balance

And this is how you would use it:

---
mywallet=Wallet()
mywallet.getPaid(50)
mywallet.spend(27)
mywallet.display()
---

-- 
Ignacio Vazquez-Abrams  <ignacio at openservices.net>





More information about the Python-list mailing list