Apparently, you tried to print the object?
If your object is printable, you should define in the class a methode __repr__() and/or a method __str__() that return the string to be printed...
print() call __str__(), but if __str__() isn't available, it fallback on __repr__() (without entering too much into details).
__str__() should be human-readable, __repr__() a way to represent the object by a string (for example, for saving the object in a text file) with the idea of converting back the string into an object...
I'll give you an example in two minutes...
Edit:
With this definition of the class
we get this behavior:
With this one:
we get:
Is this what you're after?
Re-edit: to be clear, once you've done this, you just have to do
for example...
Re-re-edit:
Of course, Python give unlimited access to everything, so you don't NEED to use __str__.
You coud do
But since it's a attempt to see how classes work, I'd say using some special methods would probably be interesting... (?)
Re-re-re-edit :
Or
since you've declared those two functions.
Though I'd say that getters are unpythonic, you shouldn't write Get_XXX methods. That's inherited from other languages like Java or C++, but that doesn't make sense in Python.
If your object is printable, you should define in the class a methode __repr__() and/or a method __str__() that return the string to be printed...
print() call __str__(), but if __str__() isn't available, it fallback on __repr__() (without entering too much into details).
__str__() should be human-readable, __repr__() a way to represent the object by a string (for example, for saving the object in a text file) with the idea of converting back the string into an object...
I'll give you an example in two minutes...
Edit:
With this definition of the class
Code:
class ctest :
def __init__(self, value=None) :
self.value = value
Code:
In [1]: test = ctest(42)
In [2]: print(test)
<__main__.ctest object at 0x07716E90>
With this one:
Code:
class ctest :
def __init__(self, value=None) :
self.value = value
def __str__(self) :
return "the value is "+str(self.value)
we get:
Code:
In [3]: test = ctest(42)
In [4]: print(test)
the value is 42
Is this what you're after?
Re-edit: to be clear, once you've done this, you just have to do
Code:
def displayPokemons(pokemon_list) :
for poke in Pokemon :
print(poke)
Re-re-edit:
Of course, Python give unlimited access to everything, so you don't NEED to use __str__.
You coud do
Code:
def displayPokemons(pokemon_list) :
for poke in Pokemon :
print("Name:", poke.name)
print("Ability:", poke.ability)
But since it's a attempt to see how classes work, I'd say using some special methods would probably be interesting... (?)
Re-re-re-edit :
Or
Code:
def displayPokemons(pokemon_list) :
for poke in Pokemon :
print("Name:", poke.Get_Name() )
print("Ability:", poke.Get_Ability() )
Though I'd say that getters are unpythonic, you shouldn't write Get_XXX methods. That's inherited from other languages like Java or C++, but that doesn't make sense in Python.