background preloader

Python

Facebook Twitter

Python Tutorial: Regular Expression. The aim of this chapter of our Python tutorial is to present a detailled and descriptive introduction into regular expressions.

Python Tutorial: Regular Expression

This introduction will explain the theoretical aspects of regular expressions and will show you how to use them in Python scripts. The term "regular expression", sometimes also called regex or regexp, is originated in theoretical computer science. In theoretical computer science they are used to define a language family with certain characteristics, the so-called regular languages. A finite state machine (FSM), which accept language defined by a regular expression, exists for every regular expression. We have an implementation of (Finite State Machine in Python), Regular Expressions are used in programming languages to filter texts or textstrings.

There is an aspect of regular expressions which shouldn't go unmentioned: The syntax of regular expressions is the same for all programming and script languages, e.g. Introduction. Welcome to DreamPie! 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. Autopep8 0.8.7. A tool that automatically formats Python code to conform to the PEP 8 style guide autopep8 automatically formats Python code to conform to the PEP 8 style guide.

autopep8 0.8.7

It uses the pep8 utility to determine what parts of the code needs to be formatted. autopep8 is capable of fixing most of the formatting issues that can be reported by pep8. By default autopep8 only makes whitespace changes. Thus, by default, it does not fix E711 and E712. (Changing x == None to x is None may change the meaning of the program if x has its __eq__ method overridden. . ) $ autopep8 --aggressive <filename> Use multiple --aggressive to increase the aggressiveness level. Speed/Profiling. The lsprofcalltree.py script (referenced in comments on this blog entry) provides output which can then be used by KCachegrind to visualize the most time-consuming functions in a program, presented using tree map, call graph and list views.

Speed/Profiling

The script can be used to run a program as follows: python lsprofcalltree.py -o output.log yourprogram.py args Obviously, in the above, yourprogram.py is the program being profiled and args are the desired arguments to be supplied to the program, if any. If the -o option is omitted, a default output file will be chosen based on the name of the profiled program; here, output.log is the file which will contain the profiling results. Once the program has terminated, the results of the profiling activity saved in the output file can be visualised using KCachegrind as follows:

Python Types and Objects. Can Skim Section This oddly placed section explains the type-instance and supertype-subtype relationships, and can be safely skipped if the reader is already familiar with these OO concepts.

Python Types and Objects

Skimming over the rules below might be useful though. While we introduce many different objects, we only use two kinds of relationships (Figure 4.1, “Relationships”): is a kind of (solid line): Known to the OO folks as specialization, this relationship exists between two objects when one (the subclass) is a specialized version of the other (the superclass).

Components

Pyparsing.wikispaces. 20 July 2013 - NOTE - Pyparsing 2.0.1 was just released, and supports Python versions 2.6 and later.

pyparsing.wikispaces

If you are using Python 2.5 or older, you must specifcally install version 1.5.7. IF YOU ARE USING PYTHON 2.6 OR LATER AND ARE HAVING DIFFICULTIES INSTALLING THE LATEST PYPARSING, PLEASE MESSAGE ME IMMEDIATELY! See more info on the News page from pyparsing import Word, alphas greet = Word( alphas ) + "," + Word( alphas ) + "! " # <-- grammar defined here hello = "Hello, World! " Hello, World! The Python representation of the grammar is quite readable, owing to the self-explanatory class names, and the use of '+', '|' and '^' operator definitions.

Lxml

RPyC - Transparent, Symmetric Distributed Computing — RPyC. RPyC (pronounced as are-pie-see), or Remote Python Call, is a transparentpython library for symmetricalremote procedure calls, clustering and distributed-computing.

RPyC - Transparent, Symmetric Distributed Computing — RPyC

RPyC makes use of object-proxying, a technique that employs python’s dynamic nature, to overcome the physical boundaries between processes and computers, so that remote objects can be manipulated as if they were local. A screenshot of a Windows client connecting to a Linux server. Note that text written to the server’s stdout is actually printed on the server’s console. Getting Started. Deux développeurs en vadrouille qui se sortent les doigts du code. Les environnements virtuels Python : virtualenv et virtualenvwrapper. Valeurs et références en Python. Petit article en complément de l’article de Réchèr.

Valeurs et références en Python

Il y a plusieurs manières de passer une variable en informatique: par valeur ou par référence. Et dans les langages bas niveau comme le C, on se pose la question: “passe-t-on la valeur ? Un pointer ? Le guide ultime et définitif sur la programmation orientée objet en Python à l’usage des débutants qui sont rassurés par les textes détaillés qui prennent le temps de tout expliquer. Partie 1. Prérequis à ce tuto bien chargé : comprendre parfaitement les mots clés les plus courants (conditions, tests, pass, etc);comprendre parfaitement les fonctions (et donc les paramètres avancées en Python);comprendre la notion de référence;connaitre les structures de données de base (string, int, list, dict, etc).

Le guide ultime et définitif sur la programmation orientée objet en Python à l’usage des débutants qui sont rassurés par les textes détaillés qui prennent le temps de tout expliquer. Partie 1.

Intro. State machine en Python en l’absence d’algos récursifs bénéficiant de tail call optimisation. Ca c’est un titre qui en jette !

State machine en Python en l’absence d’algos récursifs bénéficiant de tail call optimisation

Faut dire que je tiens du maître Sokal himself. Donc, vulgarisons un peu. Ca sera un article bien prise de tête. Lisez-le un dimanche soir quand vous ne captez pas arte (et si vous ne pigez rien, c’est pas grave, revenez dans un an, moi je le fais bien avec tous les articles d’Alex Martelli). L’encoding en Python, une bonne fois pour toute. J’avais oublié la zik, je rajoute: Vous avez tous un jour eu l’erreur suivante : UnicodeDecodeError: 'machine' codec can't decode character 'trucmuche' in position x: ordinal not in range(z) Et là, pour vous en sortir, vous en avez chié des ronds de pâté. Le problème vient du fait que la plupart du temps, ignorer l’encoding marche : nous travaillons dans des environnements homogènes et toujours avec des données dans le même format, ou un format plus ou moins compatible.

Décorateur de trace. (Ceci est un post invité de xonop sous licence creative common 3.0 unported.)