oop issue
MRAB
python at mrabarnett.plus.com
Mon May 23 16:11:05 EDT 2022
On 2022-05-23 20:36, Tola Oj wrote:
> i am trying to print this code but it keeps giving me this typeerror,
> please help. the csv file format i am trying to change into a list is in a
> different module.
>
> class invest_crypto:
> crypto_current_rate = 0.05
> client_list = []
> def __init__(self, name, surname, amount_Deposited, amount_to_transfer):
> self.name = name
> self.surname = surname
> self.amount_Deposited = amount_Deposited
> self.amount_to_transfer = amount_to_transfer
>
> invest_crypto.client_list.append(self)
>
> def calculate_customer_transfer(self):
> self.customer_transfer = (self.crypto_current_rate * self.
> amount_Deposited) + self.amount_Deposited
> return self.customer_transfer
>
> @classmethod
> def access_client_details(cls):
> with open('C:\\Users\\ojomo\\OneDrive\\Desktop\\myexcel\\
> oop_learn.py\\myExperiment.py\\clientDetails.csv', 'r' ) as f:
> reader = csv.DictReader(f)
> clientDetails = list(reader)
>
> for item in clientDetails:
> invest_crypto(
> name=item.get('name'),
> surname=item.get('surname'),
> amount_Deposited=item.get('amount_deposited'),
> amount_to_transfer=item.get('amount_to_transfer')
> )
> @staticmethod
> def __repr__(self):
> return f"('{self.name}', '{self.surname}', '{self.amount_Deposited}',
> '{self.amount_to_transfer}')"
>
>
> invest_crypto.access_client_details()
> print(invest_crypto.client_list())
"this typeerror"? What type error? You haven't shown the traceback.
I'm guessing that it's complaining about the last line, where you're
calling 'client_list', which is a list. Don't call something that's not
callable!
The last line should be:
print(invest_crypto.client_list)
(I'm not going to mention the way you're creating instances that append
themselves onto a list that's on the class; that's just weird, IMHO...)
More information about the Python-list
mailing list