background preloader


Facebook Twitter

Birdback/ CPython Compilers. Of being lazy – Paul Masurel. What’s lazy evaluation about ?

Of being lazy – Paul Masurel

Some functional programming languages (like Haskell) offers a functionality called lazy evaluation by default. It consists of defering evaluation of functions to the moment their results are actually used. Instead of results, everything works as if your function call are returning the recipe to compute the actual result. In python, it is actually pretty straightforward to hack __getattr__ and __setattr__ to implement an hackish lazy evaluation as a decorator. class LazyObject(object): __slots__ = [ "_recipe", "_result", "_evaluated" ] def __init__(self, recipe): object. Let’s now check out that the evaluation is done at the last moment with a couple of “print statement”. @lazydef returns_two(): print "evaluation for good" return 2 result = returns_two()print "lazy evaluation"print result + 1 This should result in the following output.

Docopt/docopt. Myusuf3/delorean. Python String Format – Solutions Log - Marcus Kazmierczak. Every time I use Python’s string formatter, version 2.7 and up, I get it wrong and for the life of me I can’t figure out their documentation format.

Python String Format – Solutions Log - Marcus Kazmierczak

I got very used to the older % method. So I started to create my own string format cookbook. Let me know in the comments of any other good example to include. String Formatting Cookbook Number Formatting The following table shows various ways to format numbers using python’s newish str.format(), examples for both float formatting and integers. To run examples use print("FORMAT".format(NUMBER)); So to get the output of the first example, you would run: print("{:.2f}".format(3.1415926)); string.format() basics Here are a couple of example of basic string substitution, the {} is the placeholder for the substituted variables. s1 = "so much depends upon {}".format("a red wheel barrow") s2 = "glazed with {} water beside the {} chickens".format("rain", "white") Older “%” string formatter Formating a floating point number: Multiple Substitution Values.

7 Python Libraries you should know about. In my years of programming in Python and roaming around GitHub's Explore section, I've come across a few libraries that stood out to me as being particularly enjoyable to use.

7 Python Libraries you should know about

This blog post is an effort to further spread that knowledge. I specifically excluded awesome libs like requests, SQLAlchemy, Flask, fabric etc. because I think they're already pretty "main-stream". Faif/python-patterns. Erezsh/plyplus. Design Patterns In Python (@Testing Perspective)  Writing python daemons. A daemon in Unix™ and similar operating systems, is a background process, which runs without using the terminal or the X11 system as main I/O system.

writing python daemons

In other operating system, this is called service. A daemon has a very specific task to do, for example the NTP daemon keeps your computer date updated connecting to NTP servers. Many applications that require asynchronous tasks, require this kind of applications to make your life easier. For example a job queue processor for the Gearman job server can be handled with this kind of applications. A daemon, classically on most Unix™ systems, first closes the three main I/O streams: stdin, stdout and stderr, then the fork(2) system call is used, creating an image of the current process, once the call is made, an exit(1) call is made on the parent process, and the child process keeps working in background.

Currently Promoting. Python Data Analysis Library — pandas: Python Data Analysis Library. ByteplayDoc. Exploring Python Code Objects « So first of all, what is a code object?

Exploring Python Code Objects «

Many people (particularly Python haters) claim that Python is an interpreted language, but all your Python code is actually compiled before it is ever executed. This goes even for code you write interactively in the Python shell. CPython implements a virtual machine that executes a stack-based bytecode. At runtime, executable things (functions, methods, modules, class bodies, lambdas, statements, expressions, etc) are all executed as bytecode by the Python virtual machine. Static Modification of Python with Python: the AST Module - Blueprint Forge. Source code modification can be useful in a number of testing and analysis scenarios.

Static Modification of Python with Python: the AST Module - Blueprint Forge.

Here, we’ll look at how you can modify Python source code using the ast module, and some tools where this technique is used. The CPython compilation process To begin, let’s take a look at the CPython compilation process, as described in PEP 339. Detailed knowledge of these steps isn’t required for reading this article, but it helps to have a rough idea of the whole process. First, a parse tree is generated from the source code. Pyp - Python Power at the Prompt. Ls | pyp "p.replace('maybe','yes') | pp.sort() | pp[1:3] |p , p , p.strip('abc') | whitespace | p[3], 'no' | p.upper() " Pyp is a linux command line text manipulation tool similar to awk or sed, but which uses standard python string and list methods as well as custom functions evolved to generate fast results in an intense production environment.

pyp - Python Power at the Prompt

Pyed Pyper was developed at Sony Pictures Imageworks to facilitate the construction of complex image manipulation "one-liner" commands during visual effects work on Alice in Wonderland, Green Lantern, and the The Amazing Spiderman. Because pyp employs it's own internal piping syntax ("|") similar to unix pipes, complex operations can be proceduralized by feeding the output of one python command to the input of the next. This greatly simplifies the generation and troubleshooting of multistep operations without the use of temporary variables or nested parentheses. Tomerfiliba/plumbum. Kennethreitz/envoy. Ambulant/ambulant: src/pyambulant/README@6deac0e05990. Error: CSS did not load.

ambulant/ambulant: src/pyambulant/README@6deac0e05990

This may happen on the first request due to CSS mimetype issues. Try clearing your browser cache and refreshing. Tree [bfa170] default / History Ambulant Player README ====================== This directory contains version 2.5 of the Ambulant Player, a playback engine for SMIL 3.0 (or earlier) documents. NOTE: odd-numbered versions, such as this one, are moving targets: they are the current state of our development tree.