2015-11-07 52 views
0

我想寫一個python程序,並試圖學習類。我的程序如下:from:無法讀取/ var/mail/classes

class Account(): 
    def __init__(self, name, account_number, initial_amount, transactions): 
     self.name = name 
     self.no = account_number 
     self.balance = initial_amount 
     self.transactions = 0 

    def deposit(self, amount): 
     self.balance += amount 
     self.transactions += 1 

    def withdraw(self, amount): 
     self.balance -= amount 
     self.transactions += 1 

    def dump(self): 
     s = '$s, %s, balance: %s, number of transactions: %s' %\ 
      (self.name, self.no, self.balance, self.transactions) 
     print s 

在終端,當我的Python程序所在的文件夾中,我嘗試寫從類導入帳戶來測試我的程序,但錯誤的代碼,我得到的是:從:無法讀取/ var/mail/classes。這是什麼意思,我該如何解決?

回答

2

你不應該從python程序文件夾運行python。相反,你應該從你的代碼所在的目錄啓動python。

from classes import Account將首先在工作文件夾中查找名爲classes.py的文件。然後它會查看其他Python路徑。