/usr/share/doc/python-traits/examples/tutorials/doc_examples/examples/minimal.py is in python-traits 4.1.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | # Copyright (c) 2007, Enthought, Inc.
# License: BSD Style.
# minimal.py --- Minimal example of using traits.
#--[Imports]--------------------------------------------------------------------
from traits.api import HasTraits, Float, TraitError
#--[Code]-----------------------------------------------------------------------
class Person(HasTraits):
weight = Float(150.0)
#--[Example*]-------------------------------------------------------------------
# instantiate the class
joe = Person()
# Show the default value
print joe.weight
# Assign new values
joe.weight = 161.9 # OK to assign a float
print joe.weight
joe.weight = 162 # OK to assign an int
print joe.weight
# The following line causes a traceback:
try:
joe.weight = 'average' # Error to assign a string
print "You should not see this message."
except TraitError:
print "You can't assign a string to the 'weight' trait."
|