Code Monkey home page Code Monkey logo

dynscope's Introduction

-- restructuredtext --

Dynamic Scope for Python

This package implements simple dynamic scope syntactic sugar for Python. It allows to (IMO elegantly) use dynamically scoped variables where you need them with a scheme-like semantic.

Install is quite standard:

easy_install dynscope

or just download the sources and run setup.py install. There are testcases you can run with setup.py test, too.

I test and work with it under Python 2.6.

How to use dynamically scoped variables

>>> from dynscope import flet, fluid >>> with flet(anton=5, berta=6): >>> print fluid.anton*fluid.berta >>> print fluid.anton*fluid.berta

The first print will print 30, the second one will raise an exception, since those variables are not defined.

There is a base-layer of fluid definitions (think of them as normal globals, only that they are per-thread or per-coroutine if using for example gevent with full patching) that you can use, too. But it's often much better style to restrict fluids to the dynamic scope that actually expects them. Unrestricted globals are far more often the wrong choice than the right choice. But where you can make use of them is to set defaults for dynamically scoped variables so that functions can run outside flet scopes.

dynscope's People

Contributors

samanklesaria avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.