Installation
GarlicSim is dead , but still available :
C:\Python27\Scripts>pip search garlicsim garlicsim_lib - Collection of GarlicSim simulation packages garlicsim_lib_py3 - Collection of GarlicSim simulation packages garlicsim_wx - GUI for garlicsim, a Pythonic framework for computer simulations garlicsim - Pythonic framework for working with simulations garlicsim_py3 - Pythonic framework for working with simulations
Use pip install garlicsim to install it.
Using
According to the Python style guide :
Import is always placed at the top of the file, immediately after any module comments and docstrings, as well as before modular globals and constants.
Import should be grouped in the following order:
- import standard library
- Third Party Related Imports
- import local applications / libraries
You must put an empty line between each import group.
>>> import garlicsim.general_misc.context_manager as CM >>> help(CM) Help on module garlicsim.general_misc.context_manager in garlicsim.general_misc: NAME garlicsim.general_misc.context_manager - Defines the `ContextManager` and `ContextManagerType` classes. FILE c:\python27\lib\site-packages\garlicsim\general_misc\context_manager.py DESCRIPTION Using these classes to define context managers allows using such context managers as decorators (in addition to their normal use) and supports writing context managers in a new form called `manage_context`. (As well as the original forms). [...] >>> from garlicsim.general_misc.context_manager import ContextManager >>> help(ContextManager) Help on class ContextManager in module garlicsim.general_misc.context_manager: class ContextManager(__builtin__.object) | Allows running preparation code before a given suite and cleanup after.
Alternative
It looks like already in Python 3.2 :
class contextlib.ContextDecorator - the base class that allows the context manager, which will also be used as a decorator.
And the contextmanager is as old as Python 2.5 :
from contextlib import contextmanager @contextmanager def tag(name): print "<%s>" % name yield print "</%s>" % name >>> with tag("h1"): ... print "foo" ... <h1> foo </h1>
Cees timmerman
source share