TempConverter example

4 views
Skip to first unread message

no one

unread,
Mar 25, 2010, 7:00:32 AM3/25/10
to Better Python
I'm having a play with the fork of Trellis, Reaction, and had a quick
question, as the .txt files included are a bit confusing, I can't
always tell when something corresponds to Trellis or to Reaction.

I wanted to do a quick demonstration of the TempConverter example in
the Trellis docs, and tried converting to what I'm guessing is more or
less correct for Reaction... so:

class TempConverter(Component):
F = maintain(lambda self: self.C * 1.8 + 32)
C = maintain(lambda self: (self.F - 32)/1.8)
@effect_method
def show_values(self):
print "Celsius......", self.C
print "Fahrenheit...", self.F

Then:
tc = TempConverter(C=100)
tc.F = 32
tc.C = -40
etc...

However the instantiation of TempConverter(C=100) gives me an error
(included below).

Do you have a simple example corresponding to the circular
dependencies of TempConverter, or is the error obvious to you?

Cheers!

- Charlie

Stack trace of errors follows....

------------------------

tc = TempConverter(C=100)

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.5/site-packages/DecoratorTools-1.7-py2.5.egg/
peak/util/decorators.py", line 634, in __call__
File "/Users/charlie/Dev/svnroot/sandbox/charlie/__init__.py", line
96, in __class_call__
File "build/bdist.macosx-10.5-i386/egg/mext/reaction/stm/
controllers.py", line 239, in __exit__
File "build/bdist.macosx-10.5-i386/egg/mext/reaction/stm/
controllers.py", line 264, in new_txn
File "build/bdist.macosx-10.5-i386/egg/mext/reaction/stm/
controllers.py", line 239, in __exit__
File "build/bdist.macosx-10.5-i386/egg/mext/reaction/stm/
controllers.py", line 274, in _new_txn
File "build/bdist.macosx-10.5-i386/egg/mext/reaction/stm/
transactions.py", line 276, in __exit__
File "build/bdist.macosx-10.5-i386/egg/mext/reaction/stm/
transactions.py", line 549, in __exit__
File "build/bdist.macosx-10.5-i386/egg/mext/reaction/stm/
transactions.py", line 475, in __exit__
File "build/bdist.macosx-10.5-i386/egg/mext/reaction/stm/
controllers.py", line 274, in _new_txn
File "build/bdist.macosx-10.5-i386/egg/mext/reaction/stm/
controllers.py", line 264, in new_txn
File "/Users/charlie/Dev/svnroot/sandbox/charlie/__init__.py", line
84, in __class_call__
File "/Library/Python/2.5/site-packages/DecoratorTools-1.7-py2.5.egg/
peak/util/decorators.py", line 649, in __class_call__
File "/Users/charlie/Dev/svnroot/sandbox/charlie/__init__.py", line
46, in init_attrs
File "build/bdist.macosx-10.5-i386/egg/mext/reaction/component/
attrs.py", line 172, in __set__
AttributeError

Sergey Schetinin

unread,
Mar 25, 2010, 9:53:58 PM3/25/10
to better-python
Basically that initial example from Trellis documentation was a very poor choice. Not only it relies on certain hacky solutions in Trellis itself, if you continue to write your code like that you'll eventually get tons of problems, guaranteed. Reaction intentionally prohibits code like that. So, the proper way to implement TempConverter is something like this (assuming py2.6):

from mext.reaction import *

@effect_method
def prnt(*args):
    print ' '.join(map(str, args))


class TempConverter(Component):
    F = attr(0)
    @property
    def C(self):
        return (self.F - 32)/1.8
    @C.setter
    def C(self, val):
        self.F = val * 1.8 + 32

    @maintain
    def show_values(self):
        prnt("Celsius......", self.C)
        prnt("Fahrenheit...", self.F)



tc = TempConverter(C=100)
tc.F = 32
tc.C = -40

I want to stress once again that Trellis' TempConverter is absolutely awful.





--
Mailing list: http://groups.google.com/group/better-python
Unsubscribe: better-pytho...@googlegroups.com

To unsubscribe from this group, send email to better-python+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.



--
Best Regards,
Sergey Schetinin

http://s3bk.com/ -- S3 Backup
http://word-to-html.com/ -- Word to HTML Converter
Reply all
Reply to author
Forward
0 new messages