/usr/share/doc/python-traits/examples/tutorials/doc_examples/examples/all_wildcard.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 35 36 37 38 39 40 41 42 | # Copyright (c) 2007, Enthought, Inc.
# License: BSD Style.
# all_wildcard.py --- Example of trait attribute wildcard rules
#--[Imports]--------------------------------------------------------------------
from traits.api import Any, Str, Int, HasTraits, TraitError
#--[Code]-----------------------------------------------------------------------
class Person ( HasTraits ):
# Normal, explicitly defined trait:
name = Str
# By default, let all traits have any value:
_ = Any
# Except for this one, which must be an Int:
age = Int
#--[Example*]-------------------------------------------------------------------
# Create a sample Person:
bill = Person()
# These assignments should all work:
bill.name = 'William'
bill.address = '121 Drury Lane'
bill.zip_code = 55212
bill.age = 49
# This should generate an error (must be an Int):
print 'Attempting to assign a string to an Int trait object...\n'
try:
bill.age = 'middle age'
except TraitError, c:
print 'TraitError: ', c, '\n'
# Display the final results:
bill.print_traits()
|