background preloader

Learn

Facebook Twitter

Oop - Python @classmethod and @staticmethod for beginner? Understanding Python Decorators in 12 Easy Steps! Ok, perhaps I jest.

Understanding Python Decorators in 12 Easy Steps!

As a Python instructor, understanding decorators is a topic I find students consistently struggle with upon first exposure. That’s because decorators are hard to understand! Getting decorators requires understanding several functional programming concepts as well as feeling comfortable with some unique features of Python’s function definition and function calling syntax. Мега-Учебник Flask, Часть 3: Формы. Python Multithreaded Programming. Running several threads is similar to running several different programs concurrently, but with the following benefits − Multiple threads within a process share the same data space with the main thread and can therefore share information or communicate with each other more easily than if they were separate processes.Threads sometimes called light-weight processes and they do not require much memory overhead; they care cheaper than processes.

Python Multithreaded Programming

Will it Python. Slender Means I'd like to drop my trousers to the world.

Will it Python

I am a man of means, of slender means. Django Best Practices. Show Navigation Navigation.

Django Best Practices

DRY Principles (Decorators) Python decorators are a powerful tool to remove redundancy.

DRY Principles (Decorators)

Along with modularizing functionality into appropriate bite-sized methods, it makes even the most complex workflows into concise functionality. For example, let's look at the Django web framework, which handles requests by methods which receive a method object and return a response object: def handle_request(request): return HttpResponse("Hello, World") A case I ran into recently was having to write several api methods which must: Linux System Mining with Python. In this article, we will explore the Python programming language as a tool to retrieve various information about a system running Linux.

Linux System Mining with Python

Let’s get started. Which Python? When I refer to Python, I am referring to CPython 2 (2.7 to be exact). I will mention it explicitly when the same code won’t work with CPython 3 (3.3) and provide the alternative code, explaining the differences. Just to make sure that you have CPython installed, type python or python3 from the terminal and you should see the Python prompt displayed in your terminal. Note Please note that all the programs have their first line as #! Exploring the platform module The platform module in the standard library has a number of functions which allow us to retrieve various system information.

>>> import platform >>> platform . uname () ('Linux', 'fedora.echorand', '3.7.4-204.fc18.x86_64', '#1 SMP Wed Jan 23 16:44:29 UTC 2013', 'x86_64') >>> platform . uname ()[ 0 ] 'Linux' Understanding the FFT Algorithm. The Fast Fourier Transform (FFT) is one of the most important algorithms in signal processing and data analysis.

Understanding the FFT Algorithm

Learn Python The Hard Way. Learn Python!!!!!! Better Python APIs. Python Attributes and Methods. Fast Non-Standard Data Structures for Python. Python provides great built-in types like dict, list, tuple and set; there are also array, collections, heapq modules in the standard library; this article is an overview of external lesser known packages with fast C/C++ based data structures usable from Python.

Fast Non-Standard Data Structures for Python

Note. What is a metaclass in Python. Python threads synchronization: Locks, RLocks, Semaphores, Conditions, Events and Queues. This article describes the Python threading synchronization mechanisms in details.

Python threads synchronization: Locks, RLocks, Semaphores, Conditions, Events and Queues

We are going to study the following types: Lock, RLock, Semaphore, Condition, Event and Queue. Also, we are going to look at the Python internals behind those mechanisms. The source code of the programs below can be found at github.com/laurentluce/python-tutorials under threads/. First, let’s look at a simple program using the threading module with no synchronization. Threading. Python Types and Objects. Pickle. The pickle module implements a fundamental, but powerful algorithm for serializing and de-serializing a Python object structure.

Pickle

“Pickling” is the process whereby a Python object hierarchy is converted into a byte stream, and “unpickling” is the inverse operation, whereby a byte stream is converted back into an object hierarchy. Pickling (and unpickling) is alternatively known as “serialization”, “marshalling,” or “flattening”, however, to avoid confusion, the terms used here are “pickling” and “unpickling”. This documentation describes both the pickle module and the cPickle module. Warning The pickle module is not secure against erroneous or maliciously constructed data. 11.1.1.

The pickle module has an optimized cousin called the cPickle module. The data streams the two modules produce are guaranteed to be interchangeable. The pickle module differs from marshal in several significant ways: Python Scientific Lecture Notes. Python4Astronomers. A naive simulator of gravity, written in Python. (Coded during a 2010 summer night... updated with Runge-Kutta solver during Xmas 2012 weekend... Reddit-ed) I've always been fascinated by space - ever since I read "The Family of the Sun", when I was young. And I always wanted to simulate what I've read about Newton's law of gravity, and see what happens in... a universe of my own making... :‑) So eventually, I sat down and did it. The following code "sprays" planets randomly, inside a 900x600 window (the values are in the code, change them at will). Gravity, inversely proportional to the square of the distance, and linearly proportional to the product of the two masses Elastic "mergings" of two planets if they are close enough to touch: a merged planet is then created, that maintains the momentum (mass times velocity) and the mass of the two merged ones.

Self. PyML - machine learning in Python. Think Bayes - Bayesian Statistics Made Simple (PDF) Basic Sentiment Analysis with Python. 01 nov 2012 [Update]: you can check out the code on Github In this post I will try to give a very introductory view of some techniques that could be useful when you want to perform a basic analysis of opinions written in english. These techniques come 100% from experience in real-life projects. Don't expect a theoretical introduction of Sentiment Analysis and the multiple strategies out there to achieve opinion mining, this is only a practical example of applying some basic rules to extract the polarity (positive or negative) of a text. Collections. New in version 2.4. Source code: Lib/collections.py and Lib/_abcoll.py This module implements specialized container datatypes providing alternatives to Python’s general purpose built-in containers, dict, list, set, and tuple.

In addition to the concrete container classes, the collections module provides abstract base classes that can be used to test whether a class provides a particular interface, for example, whether it is hashable or a mapping. MapReduce. MapReduce is a programming model for processing large amounts of data in a parallel and distributed fashion. It is useful for large, long-running jobs that cannot be handled within the scope of a single request, tasks like: Analyzing application logsAggregating related data from external sourcesTransforming data from one format to anotherExporting data for external analysis With the App Engine MapReduce library, your code can run efficiently and scale automatically.

App Engine takes care of the details of partitioning the input data, scheduling execution across a set of machines, handling failures, and reading/writing to the Google Cloud platform. Overview App Engine MapReduce is an open-source library that is built on top of App Engine services, including Datastore and Task Queues. There are no usage charges associated with the MapReduce library. Recommending friends with MapReduce and Python. MapReduce with MongoDB and Python. The Flask Mega-Tutorial.

Flask and MongoEngine. Introduction This tutorial describes the process for creating a basic tumblelog application using the popular Flask Python web-framework in conjunction with the MongoDB database.