0

I have a question with OOP and best practice. I have only recently grasped OOP in Python. My query is with user input. Most of the examples online do not include it. Is the following code correct interms of OOP best practice or is it very messy with ' ' these as the parameters?

class Userinput(object):

    def __init__(self,name):
        self.name = name

    def askuser(self,call):
        self.call = str(input('Enter in a letter  '))
        print(self.call)


a = Userinput('Test')
a.askuser('')
1
  • 1
    Do you realize that neither self.name nor the call parameter are used in any way? Also, in python 3, input always returns a string. Commented Dec 17, 2015 at 11:07

1 Answer 1

2

Your Userinput class is not providing any value, so just kill it. Classes and OOP are not the only way to write good Python. In your case, stick with a simple function.

Sign up to request clarification or add additional context in comments.

3 Comments

How exactly would I change it to make it a more viable OOP?
You don't, that's my point. Don't try to jam everything into OOP, it's a mistake. It's simple procedural code, let it be simple.
Just keep practicing Python, and don't think about OOP yet. OOP can be misused and just make things more complicated than it needs to be. I found this video to be interesting, check it out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.