background preloader

Python fr:Table des Matières

Python fr:Table des Matières

The Python Tutorial — Python v2.7.1 documentation Python is an easy to learn, powerful programming language. It has efficient high-level data structures and a simple but effective approach to object-oriented programming. Python’s elegant syntax and dynamic typing, together with its interpreted nature, make it an ideal language for scripting and rapid application development in many areas on most platforms. The Python interpreter and the extensive standard library are freely available in source or binary form for all major platforms from the Python Web site, and may be freely distributed. The same site also contains distributions of and pointers to many free third party Python modules, programs and tools, and additional documentation. The Python interpreter is easily extended with new functions and data types implemented in C or C++ (or other languages callable from C). This tutorial introduces the reader informally to the basic concepts and features of the Python language and system.

Python fr:Préface You have seen how you can reuse code in your program by defining functions once. What if you wanted to reuse a number of functions in other programs that you write? As you might have guessed, the answer is modules. There are various methods of writing modules, but the simplest way is to create a file with a .py extension that contains functions and variables. Another method is to write the modules in the native language in which the Python interpreter itself was written. A module can be imported by another program to make use of its functionality. Example (save as module_using_sys.py): import sys print('The command line arguments are:')for i in sys.argv: print i print '\n\nThe PYTHONPATH is', sys.path, '\n' $ python module_using_sys.py The command line arguments are: module_using_sys.py we are arguments The PYTHONPATH is ['/tmp/py', # many entries here, not shown here '/Library/Python/2.7/site-packages', '/usr/local/lib/python2.7/site-packages'] How It Works 11.1. 11.2. 11.3. 11.4. 11.5.

Programming with PyUSB 1.0 Who's who First of all, let's give an overview on the PyUSB modules. PyUSB modules are under the usb package. For example, to import the core module, you do as so: >>> import usb.core >>> dev = usb.core.find() Let's get it started Following is a simplistic program that sends the 'test' string to the first OUT endpoint found: import usb.core import usb.util # find our device dev = usb.core.find(idVendor=0xfffe, idProduct=0x0001) # was it found? The first two lines import PyUSB package modules. usb.core is the main module, and usb.util contains utility functions. Then, we look for the endpoint we are interested. If we know the endpoint address in advance, we could just call the write function from the device object: dev.write(1, 'test', 0) Here we write the string 'test' at endpoint address 1 of the interface number 0. What's wrong? Every function in PyUSB raises an exception in case of an error. You can also use the PyUSB log funcionality. By default the messages are sent to sys.stderr. Wow!

Snyppets - Python snippets pt This page contains a bunch of miscellaneous Python code snippets, recipes, mini-guides, links, examples, tutorials and ideas, ranging from very (very) basic things to advanced. I hope they will be usefull to you. All snippets are kept in a single HTML page so that you can easily ❶save it for offline reading (and keep on a USB key) ❷search in it. Note that scripts that do some web-scraping may not work anymore due to website changes. The web is an evolving beast :-) (Don't forget to read my main Python page ( ): there is handful of other programs and a guides.) Advertising To avoid dodgy websites,install WOT Send a file using FTP Piece of cake. import ftplib # We import the FTP module session = ftplib.FTP('myserver.com','login','passord') # Connect to the FTP server myfile = open('toto.txt','rb') # Open the file to send session.storbinary('STOR toto.txt', myfile) # Send the file myfile.close() # Close the file session.quit() # Close FTP session Still hungry ? #!

Cookbook Here is a collection of code fragments demonstrating some features of the OpenCV Python bindings. Convert an image >>> import cv >>> im = cv . LoadImageM ( "building.jpg" ) >>> print type ( im ) <type 'cv.cvmat'> >>> cv . SaveImage ( "foo.png" , im ) Resize an image To resize an image in OpenCV, create a destination image of the appropriate size, then call Resize . >>> import cv >>> original = cv . Compute the Laplacian >>> import cv >>> im = cv . Using GoodFeaturesToTrack To find the 10 strongest corner features in an image, use GoodFeaturesToTrack like this: >>> import cv >>> img = cv . Using GetSubRect GetSubRect returns a rectangular part of another image. >>> import cv >>> img = cv . Using CreateMat, and accessing an element >>> import cv >>> mat = cv . PIL Image to OpenCV (For details on PIL see the PIL handbook .) >>> import Image , cv >>> pi = Image . open ( 'building.jpg' ) # PIL image >>> cv_im = cv . OpenCV to PIL Image >>> import Image , cv >>> cv_im = cv . NumPy and OpenCV with channels.

PythonInterface Information on this page is deprecated, check the latest always-up-to-date documentation at . Starting with OpenCV release 2.2 , OpenCV will have completed it's new Python interface to cover all the C and C++ functions directly using numpy arrays. (The previous Python interface is described in SwigPythonInterface .) See notes on new developments at OpenCV Meeting Notes 2010-09-28 under "Vadim" subsection. Some highlights of the new bindings: single import of all of OpenCV using "import cv" OpenCV functions no longer have the "cv" prefix Simple types like CvRect and CvScalar use Python tuples Sharing of Image storage, so image transport between OpenCV and other systems (e.g. numpy and ROS) is very efficient Full documentation for the Python functions in Cookbook Convert an image import cv cv.SaveImage("foo.png", cv.LoadImage("foo.jpg")) Compute the Laplacian Notes

wxGlade: a GUI builder for wxWidgets/wxPython wxGlade: a GUI builder for wxWidgets/wxPython NOTE: This version of the tutorial is in sync with the current wxGlade on CVS, so some parts of it might not apply to the latest release. wxGlade Tutorial The aim of this minimal tutorial is to give an overview of wxGlade and its functionalities: despite its very short length, it is (hopefully) complete enough to make you understand how the application works, through a step-by-step description of the creation of a frame containing a notebook with some controls, a menubar and a statusbar. Before we start, let me apologize for my English: it's not my native language (I'm Italian), so it is very far from perfection. 1. To create a new frame, click on the appropriate button of the "palette" ( ): a dialog asking for the name of the class of the new window is displayed: choose the name you prefer, but remember that it must be a valid name for a Python (or C++) class. Now the frame is displayed, and the properties window changes to show the attributes of the widget just created. 2. 3. 4. ). 5. 6.

Related: