Created
October 13, 2019 14:52
-
-
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()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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