Re: oop issue

2022-05-23 Thread Avi Gross via Python-list

invest_crypto.client_list.append(self)

I am wondering about the phrasing above.

When you are in the dunder init function, you normally create and change items 
in YOURSELF so why is your code not changing self.crypto_client_list?

And what are you appending to before ever creating it? Would it kill you to 
create some form of container in the main class definition initialized 
appropriately to some variation of empty?

I won't claim to fully understand what the code wants to do. Adding yourself to 
the list of clients may make sense to you but if you understand object oriented 
programming, you may have an inkling that objects need to be CREATED somewhere 
before they can be used. Most of your code looks like it is DEFINING an object. 
The last few lines try to access a method in an object that has never been 
instantiated. Yes, you do have a way to store methods in a class and call them 
without any objects but this is not a case like that.

You need something like "myobj = invest_crypto(args)" and then the rest of your 
code can do changes and calculations and perhaps create other similar or 
different objects. You seem to be using a method that reads in a file and dumps 
a version of the contents and that might work if you did a line like this next: 
"myobj.access_client_details()" albeit not how I would name it or do it.

And, of course, your print() again names the class, not an instance of a class. 

Your code wraps in a few places and I wonder if it contains errors as in this 
set of lines:
        return f"('{self.name}', '{self.surname}', '{self.amount_Deposited}',
        '{self.amount_to_transfer}')"

Is that really how you think you set up a formatted string? 

Even if you get that working, how does the print statement know what to do with 
a list of objects?

Some might design a method you can call to print the contents of a list which 
would loop over the list. But is there ever more than one client (yourself) in 
the list?

The above rambling is just reflecting my opinion that you have not learned 
enough or thought it through and may even be copying and modifying various 
snippets of code perhaps from places where it works to a place that might be 
better designed from scratch.

Have fun. As someone else mentioned, smaller more focused examples may work 
better to get you up to speed, but then again, we often find out someone is 
given a homework assignment ...




-Original Message-
From: Tola Oj 
To: python-list@python.org
Sent: Mon, May 23, 2022 4:54 pm
Subject: oop issue

i just finished learning oop as a beginner and trying to practice with it
but i ran into this typeerror issue, help please.

Traceback (most recent call last):
  File
"c:\Users\ojomo\OneDrive\Desktop\myexcel\oop_learn.py\myExperiment.py\mainMain.py",
line 36, in 
    print(invest_crypto.client_list)
TypeError: invest_crypto.__repr__() missing 1 required positional argument:
'self'

this is my code below:
import csv
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)
-- 
https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: oop issue

2022-05-23 Thread Peter Otten

On 23/05/2022 22:54, Tola Oj wrote:

i just finished learning oop as a beginner and trying to practice with it
but i ran into this typeerror issue, help please.

Traceback (most recent call last):
   File
"c:\Users\ojomo\OneDrive\Desktop\myexcel\oop_learn.py\myExperiment.py\mainMain.py",
line 36, in 
 print(invest_crypto.client_list)
TypeError: invest_crypto.__repr__() missing 1 required positional argument:
'self'



 @staticmethod
 def __repr__(self):
 return f"('{self.name}', '{self.surname}', '{self.amount_Deposited}',
'{self.amount_to_transfer}')"


What are you trying to achieve with the staticmethod decorator?
--
https://mail.python.org/mailman/listinfo/python-list


oop issue

2022-05-23 Thread Tola Oj
i just finished learning oop as a beginner and trying to practice with it
but i ran into this typeerror issue, help please.

Traceback (most recent call last):
  File
"c:\Users\ojomo\OneDrive\Desktop\myexcel\oop_learn.py\myExperiment.py\mainMain.py",
line 36, in 
print(invest_crypto.client_list)
TypeError: invest_crypto.__repr__() missing 1 required positional argument:
'self'

this is my code below:
import csv
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)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: oop issue

2022-05-23 Thread MRAB

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...)

--
https://mail.python.org/mailman/listinfo/python-list


oop issue

2022-05-23 Thread Tola Oj
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())
-- 
https://mail.python.org/mailman/listinfo/python-list