Jul 9, 2017 12:38 PM
(This post was last modified: Jul 9, 2017 01:40 PM by JuiceWater.)
A few hours ago I decided that I wanted to learn Python. I only have experience with static languages like C and Java, so I'm still trying to get used to Python's whitespace rules and dynamic variables, but for the most part I've been able to pick it up very quickly.
I've just learned the basics of how classes are defined, and I tried to make one myself:
I always get this error:
And in line 10, where I try to call print_info() from the constructor, it is underlined with the tooltip:
Really, how is it not defined?❓ print_info() should have been defined before the interpreter even reached line 10, no?
Any explanations would be much appreciated. 🤝
I've just learned the basics of how classes are defined, and I tried to make one myself:
Code
class dog:
def print_info(self, dog_name, dog_weight, dog_breed):
print(dog_name + " is a " + dog_breed + " who weighs " + dog_weight + "lbs.")
def __init__(self, name, weight, breed):
self.name = name
self.weight = weight
self.breed = breed
print_info(name, weight, breed)
sparky = dog("Sparky", "50", "dalmatian")I always get this error:
Code
File "c:\Users\Juice\Workspace\python\learning\pythony.py", line 12, in <module>
sparky = dog("Sparky", "50", "dalmatian")
File "c:\Users\Juice\Workspace\python\learning\pythony.py", line 10, in __init__
print_info(name, weight, breed)
NameError: name 'print_info' is not definedAnd in line 10, where I try to call print_info() from the constructor, it is underlined with the tooltip:
Code
E0602:Undefined variable 'print_info'Really, how is it not defined?❓ print_info() should have been defined before the interpreter even reached line 10, no?
Any explanations would be much appreciated. 🤝


