Getting class atributte in method in python

I have this class and method:

class Person(object):            
    def __init__(self, name):
          self.name = personname
          self.surname = personsurname
    def changenameorsurname(self, x, y):
         self.x = y
         return
AdamSmith = Person ("Adam", "Smith")

I want to use method changenameorsurname to change AdamSmith's name or surname but if I use this code I'm getting name error.

AdamSmith.changenameorsurname(personname, Dave)

Name Error: name personname is not defined.

Is there elegant way to reference personname in code like this? Or do I have to make two separate methods like this:

def changename(self,  y):
             self.name = y
             return
AdamSmith.changename(Dave)


from Recent Questions - Stack Overflow https://ift.tt/3aYfkZV
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Hibernate Search - Elasticsearch with JSON manipulation

Spring Elasticsearch Operations