On 05/12/2012 16:58, Steven D'Aprano wrote:
And here is how it should be written in Python:
class Example(object):
def __init__(self, value):
self.x = value
instance = Example(42)
print instance.x # gives 42
instance.setx(23)
And introduce error handling while we're at it? Should we consider a
CutAndPasteError in Python? :)
c:\Users\Mark\MyPython>type mytest.py
class Example(object):
def __init__(self, value):
self.x = value
instance = Example(42)
print(instance.x) # gives 42
instance.setx(23)
c:\Users\Mark\MyPython>mytest.py
42
Traceback (most recent call last):
File "C:\Users\Mark\MyPython\mytest.py", line 8, in <module>
instance.setx(23)
AttributeError: 'Example' object has no attribute 'setx'
--
Cheers.
Mark Lawrence.
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor