background preloader

Python for life

Facebook Twitter

Style Guide for Python Code. Code should be written in a way that does not disadvantage other implementations of Python (PyPy, Jython, IronPython, Cython, Psyco, and such).For example, do not rely on CPython's efficient implementation of in-place string concatenation for statements in the form a += b or a = a + b.

Style Guide for Python Code

This optimization is fragile even in CPython (it only works for some types) and isn't present at all in implementations that don't use refcounting. In performance sensitive parts of the library, the ''.join() form should be used instead. This will ensure that concatenation occurs in linear time across various implementations.Comparisons to singletons like None should always be done with is or is not, never the equality operators.Also, beware of writing if x when you really mean if x is not None -- e.g. when testing whether a variable or argument that defaults to None was set to some other value. The other value might have a type (such as a container) that could be false in a boolean context! The Hitchhiker’s Guide to Python! Greetings, Earthling!

The Hitchhiker’s Guide to Python!

Welcome to The Hitchhiker’s Guide to Python. This is a living, breathing guide. If you’d like to contribute, fork us on GitHub! This handcrafted guide exists to provide both novice and expert Python developers a best practice handbook to the installation, configuration, and usage of Python on a daily basis. This guide is opinionated in a way that is almost, but not quite, entirely unlike Python’s official documentation. Let’s get started! Pysnip, a package for running large Python jobs from LaTeX. Embedding Python in LaTeX. Recently, while browsing the archives of the matplotlib mailing list, I stumbled upon the small python.sty package written by Martin R.

Embedding Python in LaTeX

Ehmsen. The package allows you to embed Python code in your document. When the document is compiled the code will be automatically run and its output included in the document. I’m a big fan of the Python programming language, so naturally I wanted to try it out. How it works Let’s start with a basic “hello world” example: Compiling the above code with shell escape enabled gives the following output: Not very spectacular, but the example shows how the package works: The code inside the \begin{python}... Something more advanced Her is a more interesting example: The above script loads PyX, an excellent Python graphics package, plots a function, saves the plot as a PDF and includes it using \includegraphics: Summary The python.sty package is useful as is, but the current version has a few issues: Every python environment use the same temporary files.

NumPy for Matlab Users - MATLAB® and NumPy/SciPy have a lot in common.

NumPy for Matlab Users -

But there are many differences. NumPy and SciPy were created to do numerical and scientific computing in the most natural way with Python, not to be MATLAB® clones. This page is intended to be a place to collect wisdom about the differences, mostly for the purpose of helping proficient MATLAB® users become proficient NumPy and SciPy users. NumPyProConPage is another page for curious people who are thinking of adopting Python with NumPy and SciPy instead of MATLAB® and want to see a list of pros and cons.

Matplotlib Tutorials - matplotlib plotting examples and tutorial. Prequsites Download and install python, matplotlib and numpyor pythonXY (includes all of the above and more) Changes in code are marked with red Simple plot #import matplotlib libaryimport matplotlib.pyplot as plt #define some datax = [1,2,3,4]y = [20, 21, 20.5, 20.8] #plot dataplt.plot(x, y) #show plotplt.show() Simple plot - configure the line and markers #plot dataplt.plot(x, y, linestyle="dashed", marker="o", color="green")

matplotlib Tutorials - matplotlib plotting examples and tutorial

A Byte of Python. Introduction to Programming using Python. Inc. - CVPR 2012 Turorial. Python for MATLAB Users: Promoting Open Source Computer Vision Research Thursday, June 21, 2012 Materials Source code for slides can be downloaded here.

Inc. - CVPR 2012 Turorial

Course materials (slides, code examples, virtual appliance) can be downloaded here. Course Description This tutorial is a hands-on introduction to using Python for rapid prototyping and computer vision research. The target audience is students, professors, researchers, and software developers who are interested in using Python for computer vision research. This is a full day tutorial divided into a morning and an afternoon session. Attendees who would like to participate should bring a laptop. Motivation MATLAB has long been the language of choice for rapid development in much of the computer vision community. Unfortunately, MATLAB is not a free and open source solution. Open source alternatives to MATLAB have had a large upswing is recent years. Syllabus and Schedule.