Не определяется имя класса, который присваивается переменной "name 'Account' is not defined"

Никак не могу понять в чем ошибка, помогите пожалуйста! Буду очень благодарен)

Ошибки:

Traceback (most recent call last):
  File "Bankapplication.py", line 5, in <module>
    class Account:
  File "Bankapplication.py", line 173, in Account
    writeAccount()
  File "Bankapplication.py", line 62, in writeAccount
    account = Account()
NameError: name 'Account' is not defined

Вот код:

import pickle
import os
import pathlib

class Account:
    accNo = 0
    name = ''
    deposit = 0
    type = ''

    def createAccount(self):
        self.accNo = int(input('Enter the account №: '))
        self.name = input('Enter the account holder name №: ')
        self.type = input('Enter the type of account [C/Z]: ')
        self.deposit = int(input('Enter the Initial amount (>=500 for Saving and >=1000 for current): '))
        print('\n\n\nAccount Created!)')

    def showAccount(self):
        print(f'Account number: {self.accNo}')
        print(f'Account Holder Name: {self.name}')
        print(f'Type of Account: {self.type}')
        print(f'Balance: {self.deposit}')

    def modifyAccount(self):
        print(f'Account Number: {self.accNo}, Holder name: {self.name}')
        self.name = input('Enter the new account holder name: ')
        self.type = input('Enter the new type of account: ')
        self.deposit = int(input('Modify balance: '))

    def depositAmount(self, amount):
        self.deposit += amount

    def withdrawAmount(self, amount):
        self.deposit -= amount

    def report(self):
        print(self.accNo , ' ', self.name , ' ', self.type , ' ', self.deposit)

    def getAccountNo(self):
        return self.accNo

    def getAccountHolderName(self):
        return self.name

    def getAccountType(self):
        return self.type

    def getDeposit(self):
        return self.deposit

    def Intro():
        print('\t\t\t\t*********************')
        print('\t\t\t\tBANK MANAGMENT SYSTEM')
        print('\t\t\t\t*********************')

        print('\t\t\t\tBrought To You By: ')
        print('\t\t\t\tRamil')
        print('\t\t\t\tPress any button to continue...')
        input()

    def writeAccount():
        account = Account()
        account.createAccount()
        writeAccountsFile(account)

    def displayAll():
        file = pathlib.Path('accounts.data')
        if file.exists():
            infile = open('accounts.data', 'rb')
            mylist = pickle.load(infile)
            for item in mylist:
                print(item.accNo, ' ', item.name, ' ', item.type, ' ', item.deposit)
            infile.close()
        else:
            print('No records to display')

    def displaySp(num):
        found = bool
        file = pathlib.Path('accounts.data')
        if file.exists():
            infile = open('accounts.data','rb')
            mylist = pickle.load(infile)
            infile = close()
            found = False
            for item in mylist:
                if item.accNo == num:
                    print(f"Your account balance is = {item.deposit}")
                    found = True
        else:
            print('No records to Search')
        if not found:
            print('No existing record with this number')

    def depositAndWithdraw(num1, num2):
        file = pathlib.Path('accounts.data')
        if file.exists():
            infile = open('accounts.data', 'rb')
            mylist = pickle.load(infile)
            infile.close()
            os.remove('accounts.data')
            for item in mylist:
                if item.accNo == num1:
                    if num2 == 1:
                        amount = int(input('Enter the number to deposit: '))
                        item.deposit += amount
                        print('Your account is updated')
                    elif num2 == 2:
                        amount = int(input('Enter the number to withdraw: '))
                        if amount <= item.deposit:
                            item.deposit -= amount
                        else:
                            print('You cannot withdraw larger amount(')
        else:
            print('No records to search')
        outfile = open('newaccounts.data', 'wb')
        pickle.dump(mylist, outfile)
        outfile.close()
        os.rename('newaccounts.data', 'accounts.data')

    def deleteAccount(num):
        file = pathlib.Path('accounts.data')
        if file.exists():
            infile = open('accounts.data', 'rb')
            oldlist = pickle.load(infile)
            infile.close()
            newlist = []
            for item in oldlist:
                if item.accNo != num:
                    newlist.append(item)
            os.remove('accounts.data')
            outfile = open('newaccounts.data', 'wb')
            pickle.dump(newlist, outfile)
            outfile.close()
            os.rename('newaccounts.data', 'accounts.data')

    def modifyAccount(num):
        file = pathlib.Path('accounts.data')
        if file.exists():
            infile = open('accounts.data', 'rb')
            oldlist = pickle.load(infile)
            infile.close()
            os.remove('accounts.data')
            for item in oldlist:
                if item.accNo == num:
                    item.name = input('Enter the account holder name: ')
                    item.type = input('Enter the account Type: ')
                    item.deposit = int(input('Enter the Amount: '))

            outfile = open('newaccounts.data', 'wb')
            pickle.dump(oldlist, outfile)
            outfile.close()
            os.rename('newaccounts.data', 'accounts.data')                      

    # Start of the programm
    ch = ''
    num = 0
    Intro()

    while ch != 8:
        print('\tMAIN MENU')
        print('\t 1 - NEW ACCOUNT')
        print('\t 2 - DEPOSIT AMOUNT')
        print('\t 3 - WITHDRAW AMOUNT')
        print('\t 4 - BALANCE ENQUIRY')
        print('\t 5 - ALL ACCOUNT HOLDER LIST')
        print('\t 6 - CLOSE AN ACCOUNT')
        print('\t 7 - MODIFY AN ACCOUNT')
        print('\t 8 - EXIT')
        print('\t Select your option (1-8)')
        ch = input()

        if ch == '1':
            writeAccount()
        elif ch == '2':
            num = int(input('\tEnter the account No: '))
            depositAndWithdraw(num, 1)
        elif ch == '3':
            num = int(input('\tEnter the account No: '))
            depositAndWithdraw(num, 2)
        elif ch == '4':
            num = int(input('\tEnter the account No: '))
            displaySp(num)
        elif ch == '5':
            displayAll()
        elif ch == '6':
            num = int(input('\tEnter the account No: '))
            deleteAccount(num)
        elif ch == '7':
            num = int(input('\tEnter the account No: '))
            modifyAccount(num)
        elif ch == '8':
            print('\tThanks for using bank managment system')
            break
        else:
            print("Invalid choice")

        ch = input('Press any button to continue...')

Ответы (0 шт):