background preloader

Python

Facebook Twitter

VPython. PyInstaller. 1. An Introduction to Distutils — Python v2.7.5 documentation. This document covers using the Distutils to distribute your Python modules, concentrating on the role of developer/distributor: if you’re looking for information on installing Python modules, you should refer to the Installing Python Modules chapter. 1.1.

1. An Introduction to Distutils — Python v2.7.5 documentation

Concepts & Terminology Using the Distutils is quite simple, both for module developers and for users/administrators installing third-party modules. As a developer, your responsibilities (apart from writing solid, well-documented and well-tested code, of course!) Packaging Python Libraries - Dive Into Python 3. You are here: Home ‣ Dive Into Python 3 ‣ Difficulty level: ♦♦♦♦♢ ❝ You’ll find the shame is like the pain; you only feel it once. ❞— Marquise de Merteuil, Dangerous Liaisons Diving In#

Packaging Python Libraries - Dive Into Python 3

PyPI - the Python Package Index. Dependencies - Is there a good dependency analysis tool for Python. Python Cheat Sheet by DaveChild. First programs in PyQt4 toolkit. HomeContents.

First programs in PyQt4 toolkit

What is __init__.py used for? ( f o o b a r . l u ) » Blog Archive » A comprehensive guide through Python packaging (a.k.a. setup scripts) One of the really useful things in python are the setup scripts.

( f o o b a r . l u ) » Blog Archive » A comprehensive guide through Python packaging (a.k.a. setup scripts)

When doing “serious” business, you really should look into them. Distutils/Tutorial. I have recently used distutils for the first time and thought I would share what I have learned.

Distutils/Tutorial

Please note: I am not a pro. All this is based on my own hacking and struggling to get things to work. I am sure there will be alternative ways to do things and that I will make mistakes. An Introduction to Python Lists. You can use the list type to implement simple data structures, such as stacks and queues. stack = [] stack.append(object) object = stack.pop() queue = [] queue.append(object) object = queue.pop(0) The list type isn’t optimized for this, so this works best when the structures are small (typically a few hundred items or smaller).

An Introduction to Python Lists

For larger structures, you may need a specialized data structure, such as collections.deque . 3.6.2 String Formatting Operations. String and Unicode objects have one unique built-in operation: the % operator (modulo).

3.6.2 String Formatting Operations

This is also known as the string formatting or interpolation operator. Given % (where is a string or Unicode object), % conversion specifications in are replaced with zero or more elements of . The effect is similar to the using sprintf() in the C language. If is a Unicode object, or if any of the objects being converted using the %s conversion are Unicode objects, the result will also be a Unicode object. If requires a single argument, may be a single non-tuple object. 3.4 Otherwise, must be a tuple with exactly the number of items specified by the format string, or a single mapping object (for example, a dictionary).

A conversion specifier contains two or more characters and has the following components, which must occur in this order: Regex replace (in Python) - a simpler way. Python Regular Expressions. A regular expression is a special sequence of characters that helps you match or find other strings or sets of strings, using a specialized syntax held in a pattern.

Python Regular Expressions

Regular expressions are widely used in UNIX world. The module re provides full support for Perl-like regular expressions in Python. The re module raises the exception re.error if an error occurs while compiling or using a regular expression. We would cover two important functions, which would be used to handle regular expressions. But a small thing first: There are various characters, which would have special meaning when they are used in regular expression. The match Function This function attempts to match RE pattern to string with optional flags. Syntax - How can I do a line break (line continuation) in Python. 7.2. re — Regular expression operations. This module provides regular expression matching operations similar to those found in Perl.

7.2. re — Regular expression operations

Both patterns and strings to be searched can be Unicode strings as well as 8-bit strings. Regular expressions use the backslash character ( '\' ) to indicate special forms or to allow special characters to be used without invoking their special meaning. This collides with Python’s usage of the same character for the same purpose in string literals; for example, to match a literal backslash, one might have to write '\\\\' as the pattern string, because the regular expression must be \\ , and each backslash must be expressed as \\ inside a regular Python string literal. Regex - Python: use regular expression to remove the white space from all lines.

Regex - How do I make this regular expression skip over a new line in Python. Python Examples - Main Page. Alsaaudio — alsaaudio v0.7 documentation. Platforms: Linux The alsaaudio module defines functions and classes for using ALSA. alsaaudio.cards() List the available cards by name (suitable for PCM objects). alsaaudio.mixers([cardindex]) List the available mixers.

alsaaudio — alsaaudio v0.7 documentation

Class alsaaudio.PCM(type=PCM_PLAYBACK, mode=PCM_NORMAL, card='default') This class is used to represent a PCM device (both for playback and recording - capture). Type - can be either PCM_CAPTURE or PCM_PLAYBACK (default).mode - can be either PCM_NONBLOCK, or PCM_NORMAL (default).card - specifies the name of the card that should be used. class alsaaudio.Mixer(control='Master', id=0, cardindex=0) This class is used to access a specific ALSA mixer. Control - Name of the chosen mixed (default is ‘Master’).id - id of mixer – More explanation needed herecardindex specifies which card should be used.

Sys.stdin. PyQt4 tutorial. This is PyQt4 tutorial. The tutorial is suited for beginners and intermediate programmers. After reading this tutorial, you will be able to program non trivial PyQt4 applications. PyQt5 tutorial is the successor of this tutorial. Table of contents E-book A unique e-book covering advanced features of the PyQt4 library: Advanced PyQt4 tutorial. Related tutorials. QApplication Class Reference. The QApplication class manages the GUI application's control flow and main settings. More... QApplication::QApplication ( int & argc, char ** argv ) Initializes the window system and constructs an application object with argc command line arguments in argv. QCoreApplication + event looping [Archive] - Qt Centre Forum. Likely the signial in the same thread will be executed immediately, while the one in the different thread will be queued.

But it could be that they both end up being queued. Don't guess. If you don't know, rely on what someone else is saying or check in the source code. The signal (the method declared in the "signals" section) is executed only once. There can be zero or more slots connected to the signal and each of them will be executed when the right time comes. GUI Programming with PyQT. Boudewijn Rempt Copyright © 2001 by Commandprompt, Inc Copyright (c) 2001 by Command Prompt, Inc. This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at ‘Distribution of substantively modified versions of this document is prohibited without the explicit permission of the copyright holder.' to the license reference or copy.

‘Distribution of the work or derivative of the work in any standard (paper) book form is prohibited unless prior permission is obtained from the copyright holder.' to the license reference or copy. Although every reasonable effort has been made to incorporate accurate and useful information into this book, the copyright holders make no representation about the suitability of this book or the information therein for any purpose. QCoreApplication Class Reference. The QCoreApplication class provides an event loop for console Qt applications. More... QCoreApplication::QCoreApplication ( int & argc, char ** argv ) Constructs a Qt kernel application. Kernel applications are applications without a graphical user interface. These type of applications are used at the console or as server processes. The argc and argv arguments are processed by the application, and made available in a more convenient form by the arguments() function. Warning: The data referred to by argc and argv must stay valid for the entire lifetime of the QCoreApplication object.

QCoreApplication::~QCoreApplication () QCoreApplication says hello. Usually we use Qt to develop a GUI application, but that is not mandatory. We could be interested in developing an application using a feature made available by Qt, like the network or XML support, without any explicit need for a graphical interface. In this case we can develop a console application, that rely on QCoreApplication, instead of the usual QApplication, to provide an even loop for the application.As an example, here is a trivial application, that says hello and then terminates. To make the code slightly more interesting, I create a class, Greeter, that provides a slot, sayHello(), to be called to greet the user: Python: Lambda Functions. Python supports the creation of anonymous functions (i.e. functions that are not bound to a name) at runtime, using a construct called "lambda".

This is not exactly the same as lambda in functional programming languages, but it is a very powerful concept that's well integrated into Python and is often used in conjunction with typical functional concepts like filter(), map() and reduce(). This piece of code shows the difference between a normal function definition ("f") and a lambda function ("g"): As you can see, f() and g() do exactly the same and can be used in the same ways. Note that the lambda definition does not include a "return" statement -- it always contains an expression which is returned. Also note that you can put a lambda definition anywhere a function is expected, and you don't have to assign it to a variable at all.

3.9 File Objects. File objects are implemented using C's stdio package and can be created with the built-in constructor file() described in section 2.1, ``Built-in Functions.''3.6 File objects are also returned by some other built-in functions and methods, such as os.popen() and os.fdopen() and the makefile() method of socket objects.

When a file operation fails for an I/O-related reason, the exception IOError is raised. This includes situations where the operation is not defined for some reason, like seek() on a tty device or writing a file opened for reading. 5. Built-in Types. 15.1. os — Miscellaneous operating system interfaces. This module provides a portable way of using operating system dependent functionality. If you just want to read or write a file see open(), if you want to manipulate paths, see the os.path module, and if you want to read all the lines in all the files on the command line see the fileinput module. For creating temporary files and directories see the tempfile module, and for high-level file and directory handling see the shutil module.

17.1. subprocess — Subprocess management. Python: How to run a command line within python? March 4th, 2008 mysurface Posted in Developer, python | Hits: 192436 | 15 Comments » Execute Linux commands in Python. Python - Basic Operators. Python - IF...ELIF...ELSE and Nested IF Statements. 17.4. signal — Set handlers for asynchronous events. Signal – Receive notification of asynchronous system events.

Simulación de sentencia «switch (case)» en Python. Python Course: Introduction into the Sys Module.