object has no attribute 'ecrire'
MRAB
python at mrabarnett.plus.com
Tue Dec 23 19:51:57 EST 2014
On 2014-12-24 00:42, fulgar36 at gmail.com wrote:
> Hello,
> I wrote this code (it was on a book)
>
> class TableauNoir:
> def __init__(self):
> self.surface=""
> def ecrire(self, message_a_ecrire):
> if self.surface != "":
> self.surface += "\n"
> self.surface+=message_a_ecrire
> it does not run on the shell and tells (object TableauNoir has no attribute 'ecrire'
> could you tell me why it does not work. in the book ecrire should be a method from the class not an attribute
> thanks
>
It works for me:
Python 3.4.2 (v3.4.2:ab2c023a9432, Oct 6 2014, 22:16:31) [MSC v.1600 64
bit (AM
D64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> class TableauNoir:
... def __init__(self):
... self.surface=""
... def ecrire(self, message_a_ecrire):
... if self.surface != "":
... self.surface += "\n"
... self.surface+=message_a_ecrire
...
>>> TableauNoir().ecrire("foo")
>>>
More information about the Python-list
mailing list