Python3属性错误int对象没有属性

时间:2017-08-01 01:00:09

标签: python-3.x attributeerror

您好我的代码出现属性错误,因为我只是一名初学程序员,我不确定哪里出错了。

import sys

class BankAccount(object):

   def __init__(self, balance = 0):
      self.balance = balance

   def withdraw(self, other):
      if other.balance <= self.balance and self.balance > 0:
         self.balance = self.balance - other.balance
      else:
         return('Insufucient funds available')

   def deposit(self, other):
      if self.balance > 0:
         self.balance = self.balance + other.balance

   def __str__(self):
      return('Your current balance is: {0:.2f} euro'.format(self.balance))

一直说AttributeError: 'int' object has no attribute 'balance'

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

namespace PinoiseDigitalStudio\Http\Controllers; use Illuminate\Http\Request; class MailController extends Controller { public function store(ContactFormRequest $request){ return \Redirect::route('contact')->with('message', 'Thanks for contacting us!'); } public function store(ContactFormRequest $request){ \Mail::send('emails.contact', array( 'name' => $request->get('name'), 'email' => $request->get('email'), 'user_message' => $request->get('message') ), function($message){ $message->from('wj@wjgilmore.com'); $message->to('wj@wjgilmore.com', 'Admin')->subject('TODOParrot Feedback'); }); return \Redirect::route('contact')->with('message', 'Thanks for contacting us!'); } } 更改为b1.withdraw(1)以及所有相似内容。

Param b1.withdraw(BankAccount(1))应该是other个实例,其BankAccount属性而不是balance