Skip to content

Instantly share code, notes, and snippets.

@sorindragan
Created October 13, 2019 14:52
Show Gist options
  • Save sorindragan/8176a66628057eaecb30aacacb5bb386 to your computer and use it in GitHub Desktop.
Save sorindragan/8176a66628057eaecb30aacacb5bb386 to your computer and use it in GitHub Desktop.
python interpreter treats 'name' as the variable 'name' that is a string other than the method name() use get_name() instead of name()
class Employee:
def __init__(self, name):
self.name = name
def get_name(self):
print(self.name)
def name(self):
print(self.name)
a = "George"
e1 = Employee("")
e1.name = a
# same as
e2 = Employee(a)
e1.get_name()
e2.get_name()
try:
e1.name()
except Exception as e:
print(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment