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. 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!)

Are: write a setup script (setup.py by convention)(optional) write a setup configuration filecreate a source distribution(optional) create one or more built (binary) distributions Each of these tasks is covered in this document. Not all module developers have access to a multitude of platforms, so it’s not always feasible to expect them to create a multitude of built distributions. 1.2. From distutils.core import setupsetup(name='foo', version='1.0', py_modules=['foo'], ) 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# Real artists ship.

Or so says Steve Jobs. Do you want to release a Python script, library, framework, or application? All of these facets of Distutils center around the setup script, traditionally called setup.py. In this chapter, you’ll learn how the setup scripts for chardet and httplib2 work, and you’ll step through the process of releasing your own Python software. skip over this code listing This version requires Python 3 or later; a Python 2 version is available separately.

""") ☞chardet and httplib2 are open source, but there’s no requirement that you release your own Python libraries under any particular license. Things Distutils Can’t Do For You# Releasing your first Python package is a daunting process. Choose a license. Directory Structure# skip over this code listing Writing Your Setup Script# 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 In this part of the PyQt4 tutorial we will learn some basic functionality. Simple example This is a simple example showing a small window. Yet we can do a lot with this window. We can resize it, maximize it or minimize it. . #! The above code shows a small window on the screen. import sys from PyQt4 import QtGui Here we provide the necessary imports.

App = QtGui.QApplication(sys.argv) Every PyQt4 application must create an application object. W = QtGui.QWidget() The QtGui.QWidget widget is the base class of all user interface objects in PyQt4. W.resize(250, 150) The resize() method resizes the widget. W.move(300, 300) The move() method moves the widget to a position on the screen at x=300, y=300 coordinates. w.setWindowTitle('Simple') Here we set the title for our window. W.show() The show() method displays the widget on the screen. Sys.exit(app.exec_()) Finally, we enter the mainloop of the application.

The exec_() method has an underscore. Figure: Simple An application icon #! Figure: Icon. 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. When doing “serious” business, you really should look into them. Setup scripts are amazingly powerful. But they don’t necessarily need to be complex. But because of this flexibility, the documentation around them seems like a lot to read.

This post attempts to summarize the important bits using a “Hello World” project and steeping through the process of creating the setup.py file: Creating a package distributionAutomatic generation of executablesVersion numbersDependency managementPublishing your package (thus also making it available for automatic dependency resolution)Some more food for thought. NOTE: The setup.py script we will construct in this post, will use two bits of code which may not work in all cases:importing the package itself (to centralize the version number)Reading the long_description content from a text-file Both methodologies have their issues. This is mostly true. Our Hello World project So far so good. <! Distutils/Tutorial. I have recently used distutils for the first time and thought I would share what I have learned.

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. Caveat Emptor. (Based on GNU/Linux) The layout of folders A proper layout of your files and folders can really save you trouble later on. Top |-- package | |-- __init__.py | |-- module.py | `-- things | |-- cross.png | |-- fplogo.png | `-- tick.png |-- runner |-- MANIFEST.in |-- README `-- setup.py top - This is called the "Distribution Root". UPDATE: How to add other files, other data and directories I have a tentative solution for when you need extra files and folders in your distributed tarball. The files runner I assume that there will be a single script file that you will use to start your Python app. Runner module.py Next is the package. Module.py It shows that it can find the data files in the things folder. 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).

For larger structures, you may need a specialized data structure, such as collections.deque . Another data structure for which a list works well in practice, as long as the structure is reasonably small, is an LRU (least-recently-used) container. Lru.remove(item) lru.append(item) If you do the above every time you access an item in the LRU list, the least recently used items will move towards the beginning of the list. Searching Lists The in operator can be used to check if an item is present in the list: if value in L: print "list contains" , value To get the index of the first matching item, use index : i = L.index(value) To count matching items, use the count method: 3.6.2 String Formatting Operations. String and Unicode objects have one unique built-in operation: the % operator (modulo). 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: The " % " character, which marks the start of the specifier. In this case no * specifiers may occur in a format (since they require a sequential parameter list). Notes: 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. 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. To avoid any confusion while dealing with regular expressions, we would use Raw Strings as r'expression'. The match Function This function attempts to match RE pattern to string with optional flags. Here is the syntax for this function − re.match(pattern, string, flags=0) Here is the description of the parameters: Example #! The search Function re.search(pattern, string, flags=0)

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. 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.

The solution is to use Python’s raw string notation for regular expression patterns; backslashes are not handled in any special way in a string literal prefixed with 'r' . So r"\n" is a two-character string containing '\' and 'n' , while "\n" is a one-character string containing a newline. 7.2.1. The special characters are: (Dot.) {m} 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.

The optional cardindex specifies which card should be queried. The default is 0. 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. exception alsaaudio.ALSAAudioError Exception raised when an operation fails for a ALSA specific reason. Or: 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 To refresh your knowledge of the Python language there is a Python tutorial on ZetCode. wxPython tutorial, PyGTK tutorial and Tkinter tutorial are tutorials for other popular Python GUI bindings.

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. Warning: The data referred to by argc and argv must stay valid for the entire lifetime of the QApplication object.

In addition, argc must be greater than zero and argv must contain at least one valid character string. The global qApp pointer refers to this application object. This application object must be constructed before any paint devices (including widgets, pixmaps, bitmaps etc.). Note: argc and argv might be changed as Qt removes command line arguments that it recognizes. Qt debugging options (not available if Qt was compiled without the QT_DEBUG flag defined): -nograb, tells Qt that it must never grab the mouse or the keyboard. See Debugging Techniques for a more detailed explanation.

-style= style, sets the application GUI style. 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.

What you say wouldn't make sense if you had a signal connected to two slots living in different threads. There is a terminology problem here. There are four entities to consider: The emit, the slot, the connection, and the "signal", which is essentially a message. If something is queued, it is the signal. There is no check for threads here, the signal is activated immediately. If something is queued, it is the signal. 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. This book is dedicated to Irina. 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 () Destroys the QCoreApplication object. void QCoreApplication::aboutToQuit () [signal] This signal is emitted when the application is about to quit the main event loop, e.g. when the event loop level drops to zero. The signal is particularly useful if your application has to do some last-second cleanup. See also quit(). QString QCoreApplication::applicationDirPath () [static] QCoreApplication says hello. Python: Lambda Functions. 3.9 File Objects. 5. Built-in Types. 15.1. os — Miscellaneous operating system interfaces. 17.1. subprocess — Subprocess management. Python: How to run a command line within python? 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 | DaW - Labs. Python Course: Introduction into the Sys Module.