1 # Reinteract generally sticks pretty close to standard Python,
2 # but the 'build' keyword is an exception. Sometimes you
3 # want to do multiple things "at once" as a single unit.
4 # The most common reason for doing this is that you are
5 # using an external module that doesn't support making
6 # copies of an object's state. You get the dreaded warning:
7 # '<object>' apparently modified, but can't copy it
9 # A simple example of build:
15 # As you can see from the above, build works a lot like
16 # Python's 'with' statement, but output's the named
17 # variable at the end of the block.
19 # We can also omit the initialization statement, and
20 # set the variable later in the block
28 # or even omit everything and just use the build: to group
29 # a number of statements.
31 import reinteract.custom_result
33 f = open(reinteract.custom_result.__file__)
39 # Finally, we can omit the variable name.
44 # This seems useless on the face of it, but the build statement
45 # optionally supports the same "context manager" protocol as the
46 # with statement, and this can be used to provide implicit
47 # context. (The reinteract author thinks that the first example
48 # in this file is the right way to do the following, but
49 # wanted to show off more complex possibilities.)
53 from reinteract.statement import Statement
56 Statement.get_current()._list = l
59 def __exit__(self, exception_type, exception_value, traceback):
60 from reinteract.statement import Statement
61 Statement.get_current()._list = None
64 from reinteract.statement import Statement
65 Statement.get_current()._list.append(v)