background preloader

Python

Facebook Twitter

Reportlab: Converting Hundreds of Images Into PDFs. Python Class Attributes are Evaluated on Declaration. In Python, class attributes are evaluated and put into memory when the class is defined (or imported).

Python Class Attributes are Evaluated on Declaration

For example, if you run the following code in an interactive interpreter, it will print out "Something __init__() called": Parsing Fixed-Length File Records with Python. 1inShare I’ve recently had to deal with parsing fixed-length file records and found struct.unpack and namedtuple to be a pretty useful and concise combination for the task: >>> from struct import unpack >>> from collections import namedtuple >>> line = ' 23C 17000' >>> Transaction = namedtuple('Transaction', 'code status amount') >>> format = '<6sc8s' # code: 6bytes, status: 1byte, amount: 8bytes >>> txn = Transaction.

Parsing Fixed-Length File Records with Python

_make(unpack(format, line)) >>> txn Transaction(code=' 23', status='C', amount=' 17000') >>> txn.code, txn.status, txn.amount (' 23', 'C', ' 17000') How-to: Python Data into Graphite for Monitoring Bliss. 0inShare We Recommend These Resources This post shows code examples in Python (2.7) for sending data to Graphite.

How-to: Python Data into Graphite for Monitoring Bliss

Once you have a Graphite server setup, with Carbon running/collecting, you need to send it data for graphing. Basically, you write a program to collect numeric values and send them to Graphite's backend aggregator (Carbon). To send data, you create a socket connection to the graphite/carbon server and send a message (string) in the format: "metric_path value timestamp\n" 1. Getting started with couchdb-python — couchdb-python v0.8 documentation. Some snippets of code to get you started with writing code against CouchDB.

1. Getting started with couchdb-python — couchdb-python v0.8 documentation

Starting off: >>> import couchdb>>> couch = couchdb.Server() This gets you a Server object, representing a CouchDB server. By default, it assumes CouchDB is running on localhost:5894. If your CouchDB server is running elsewhere, set it up like this: Invent Your Own Computer Games with Python - Learn how to program with a free ebook programming tutorial. Chapter 1.

Invent Your Own Computer Games with Python - Learn how to program with a free ebook programming tutorial

Home. Writing your first Django app, part 1. Let’s learn by example.

Writing your first Django app, part 1

Throughout this tutorial, we’ll walk you through the creation of a basic poll application. It’ll consist of two parts: A public site that lets people view polls and vote in them.An admin site that lets you add, change, and delete polls. We’ll assume you have Django installed already. You can tell Django is installed and which version by running the following command: $ python -c "import django; print(django.get_version())" If Django is installed, you should see the version of your installation. Learn Python The Hard Way, 2nd Edition — Learn Python The Hard Way, 2nd Edition.

Developer Zone - This is a distributed, volunteer project with many contributors.

Developer Zone -

The best way to join our effort is to browse around, read the last section of this page to learn about our vision and plans, and then announce your intent to help on one of the developer Mailing Lists or contact any of the folks listed on this page. SciPy is managed by a broad community of diverse users. The mailing lists are the best way to get to know the currently active community. The github activity logs also shows who has been active in the community. Respect might be given to original code authors if they are still active on the lists. Make contributions (e.g. code patches), feature requests and file bug reports by submitting a "ticket" on the Trac pages linked below. Note that NumPy contains the most basic numerical functionality, and SciPy is layered on top of NumPy to provide a much wider range of capability.

People interested in making code contributions to Numpy should take a look at the Numpy Developer Guide . Python Tutorials, more than 300, updated March 2, 2009 and carefully sorted by topic and category. The Python Standard Library — Python v2.7.2 documentation. While The Python Language Reference describes the exact syntax and semantics of the Python language, this library reference manual describes the standard library that is distributed with Python.

The Python Standard Library — Python v2.7.2 documentation

It also describes some of the optional components that are commonly included in Python distributions. Python’s standard library is very extensive, offering a wide range of facilities as indicated by the long table of contents listed below. The library contains built-in modules (written in C) that provide access to system functionality such as file I/O that would otherwise be inaccessible to Python programmers, as well as modules written in Python that provide standardized solutions for many problems that occur in everyday programming. Some of these modules are explicitly designed to encourage and enhance the portability of Python programs by abstracting away platform-specifics into platform-neutral APIs. Notes on Python variable scope. Notes on Python variable scope Example 1: The difference between global and local variables¶ Global variables are accessible inside and outside of functions.

Notes on Python variable scope

Local variables are only accessible inside the function. In the example below, the function can access both the global and the local variable. However, trying to access the local variable outside the function produces an error.