background preloader

Python Programming

Python Programming
Python Programming From Wikibooks, open books for an open world Jump to: navigation, search This book describes Python, an open-source general-purpose interpreted programming language available for a broad range of operating systems. Contents[edit] Intro[edit] Overview Getting Python Setting it up Interactive mode Self Help Basics[edit] Creating Python programs Variables and Strings Basic syntax Sequences (Strings, Lists, Tuples, Dictionaries, Sets) Data types Numbers Strings Lists Tuples Dictionaries Sets Basic Math -- redundant to "Operators" Operators Control Flow Decision Control Conditional Statements Loops Functions Scoping Input and output Files Text Modules Classes Exceptions Errors Source Documentation and Comments Idioms Advanced[edit] Decorators Context Managers Reflection Metaclasses Namespace Tips and Tricks Modules[edit] Standard library modules[edit] Standard Library Regular Expression External commands XML Tools Email Threading Sockets GUI Programming Tkinter CGI interface WSGI web programming Extracting info from web pages Math Related:  Python Learning Resources

The Python Tutorial 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 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. For a description of standard objects and modules, see The Python Standard Library. The Glossary is also worth going through.

2. Writing the Setup Script The setup script is the centre of all activity in building, distributing, and installing modules using the Distutils. The main purpose of the setup script is to describe your module distribution to the Distutils, so that the various commands that operate on your modules do the right thing. As we saw in section A Simple Example above, the setup script consists mainly of a call to setup(), and most information supplied to the Distutils by the module developer is supplied as keyword arguments to setup(). Here’s a slightly more involved example, which we’ll follow for the next couple of sections: the Distutils’ own setup script. (Keep in mind that although the Distutils are included with Python 1.6 and later, they also have an independent existence so that Python 1.5.2 users can use them to install other module distributions. #! Note that any pathnames (files or directories) supplied in the setup script should be written using the Unix convention, i.e. slash-separated. 2.1. 2.2. 2.3. 2.3.1.

Investing Wiki with Research about Companies, Investment Concepts, and more... PythonTurtle Python Programming/PyQt4 WARNING: The examples on this page are a mixture of PyQt3 and PyQt4 - use with caution! This tutorial aims to provide a hands-on guide to learn the basics of building a small Qt4 application in Python. To follow this tutorial, you should have basic Python knowledge. However, knowledge of Qt4 is not necessary. >>> import PyQt4 If no error message appears, you should be ready to go. The examples in this tutorial as easy as possible, showing useful ways to write and structure your program. Hello, world! Let's start easy: popping up a window and displaying something. #! About 7 lines of code, and that's about as easy as it can get. A Button[edit] Let's add some interaction! #! You can imagine that coding this way is not scalable nor the way you'll want to continue working. #! GUI Coding[edit] ... so we want to use Qt3 Designer for creating our GUI. pyuic testapp_ui.ui -o makes a Python file from it which we can work with. #!

FrontPage - Mentat Wiki This wiki is a collaborative environment for exploring ways to become a better thinker. Topics that can be explored here include MemoryTechniques, MentalMath, CriticalThinking, BrainStorming, ShorthandSystems, NotebookSystems, and SmartDrugs. Other relevant topics are also welcome. SiteNews Wiki Topics Mindhacker: The support page for the 2011 book by RonHaleEvans and MartyHaleEvans. MindPerformanceHacks: The support page for the 2006 book of the same name by RonHaleEvans. Easily memorize complex information - MemoryTechnique Do hard math in your head - MentalMath Improve your intelligence Think better Other pages What is a Wiki? A wiki is a web site built collaboratively by a community of users. Feel free to add your own content to this wiki. The Mentat Wiki is powered by Oddmuse, and hosted by the Center for Ludic Synergy.

A Python Book: Beginning Python, Advanced Python, and Python Exercises 2.2 Regular Expressions For more help on regular expressions, see: 2.2.1 Defining regular expressions A regular expression pattern is a sequence of characters that will match sequences of characters in a target. The patterns or regular expressions can be defined as follows: Literal characters must match exactly. Because of the use of backslashes in patterns, you are usually better off defining regular expressions with raw strings, e.g. r"abc". 2.2.2 Compiling regular expressions When a regular expression is to be used more than once, you should consider compiling it. import sys, re pat = re.compile('aa[bc]*dd') while 1: line = raw_input('Enter a line ("q" to quit):') if line == 'q': break if print 'matched:', line else: print 'no match:', line Comments: We import module re in order to use regular compiles a regular expression so that we can reuse the compiled regular expression without compiling it repeatedly. 2.2.3 Using regular expressions Notes:

Writing a Package in Python Home by Tarek Ziadé Intents of this article are: To shorten the time needed to set up everything before starting the real work, in other words the boiler-plate codeTo provide a standardized way to write packagesTo ease the use of a test-driven development approachTo facilitate the releasing process It is organized in the following four parts: A common pattern for all packages that describes the similarities between all Python packages, and how distutils and setuptools play a central role How generative programming ( can help this through the template-based approach The package template creation, where everything needed to work is setSetting up a development cycle A Common Pattern for All Packages The easiest way to organize the code of an application is to split it into several packages using eggs. Applications for a given company can have a set of eggs glued together with a master egg., the Script That Controls Everything sdist test

Python Introduction - Google's Python Class - Google Code Python is a dynamic, interpreted language. Source code does not declare the types of variables or parameters or methods. This makes the code short and flexible, and you lose the compile-time type checking in the source code. An excellent way to see how Python code works is to run the Python interpreter and type code right into it. $ python ## Run the Python interpreterPython 2.7.1 (r271:86832, Jul 31 2011, 19:30:53) [GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwinType "help", "copyright", "credits" or "license" for more information.>>> a = 6 ## set a variable in this interpreter session >>> a ## entering an expression prints its value6>>> a + 28>>> a = 'hi' ## a can hold a string just as well>>> a 'hi'>>> len(a) ## call the len() function on a string2>>> foo(a) ## try something that doesn't workTraceback (most recent call last): File " Python Program Python source files use the ".py" extension. #! Running this program from the command line looks like:

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