Python

Python Wiki
Python is a great object-oriented, interpreted, and interactive programming language. It is often compared (favorably of course ) to Lisp, Tcl, Perl, Ruby, C#, Visual Basic, Visual Fox Pro, Scheme or Java... and it's much more fun. Python combines remarkable power with very clear syntax. Getting Started Events, Courses, Conferences, Community Python Conferences - information about the Python conference scene Python Events - covers conferences, training courses and more Local User Groups - find a Python group near you Participating in the Community - where people using and producing Python get together Python Software Using this Wiki Feel free to add more useful stuff (see HelpContents and HelpOnEditing to learn how), but do us a favour and do tests in the WikiSandBox if you're not accustomed to Wiki technologies. See WikiGuidelines for details of the policies and rules governing this Wiki. See SiteImprovements for a discussion of improvements to this Wiki and other related sites.

Improve Your Python: Decorators Explained
I've previously written about "yield" and generators. In that article, I mention it's a topic that novices find confusing. The purpose and creation of decorators is another such topic (using them, however, is rather easy). In this post, you'll learn what decorators are, how they're created, and why they're so useful. A Brief Aside... Passing Functions Before we get started, recall that everything in Python is an object that can be treated like a value (e.g. functions, classes, modules). def is_even(value): """Return True if *value* is even.""" return (value % 2) == 0 def count_occurrences(target_list, predicate): """Return the number of times applying the callable *predicate* to a list element returns True.""" return sum([1 for e in target_list if predicate(e)]) my_predicate = is_evenmy_list = [2, 4, 6, 7, 9, 11]result = count_occurrences(my_list, my_predicate)print(result) The magic is in the lines my_predicate = is_even. Hopefully, this is all old hat to you. Returning Functions Raw Power

Python

BeginnersGuide
New to programming? Python is free and easy to learn if you know where to start! This guide will help you to get started quickly. Chinese Translation New to Python? Read BeginnersGuide/Overview for a short explanation of what Python is. Getting Python Next, install the Python interpreter on your computer. There are also Python interpreter and IDE bundles available, such as Thonny. There are currently two major versions of Python available: Python 2 and Python 3. See BeginnersGuide/Download for instructions to download the correct version of Python. At some stage, you'll want to edit and save your program code. Learning Python Next, read a tutorial and try some simple experiments with your new Python interpreter. If you have never programmed before, see BeginnersGuide/NonProgrammers for a list of suitable tutorials. Most tutorials assume that you know how to run a program on your computer. Once you have read a tutorial, you can browse through Python's online documentation. Need Help?

Writing your first Django app, part 1
Let’s learn by example. Throughout this tutorial, we’ll walk you through the creation of a basic poll application. It’ll consist of two parts: A public site that lets people view polls and vote in them.An admin site that lets you add, change, and delete polls. We’ll assume you have Django installed already. $ python -c "import django; print(django.get_version())" If Django is installed, you should see the version of your installation. This tutorial is written for Django 1.9 and Python 3.4 or later. See How to install Django for advice on how to remove older versions of Django and install a newer one. Where to get help: If you’re having trouble going through this tutorial, please post a message to django-users or drop by #django on irc.freenode.net to chat with other Django users who might be able to help. Creating a project¶ If this is your first time using Django, you’ll have to take care of some initial setup. $ django-admin startproject mysite Note Where should this code live? These files are:

Virtual Environments
virtualenv is a tool to create isolated Python environments. virtualenv creates a folder which contains all the necessary executables to use the packages that a Python project would need. Basic Usage Create a virtual environment for a project: $ cd my_project_folder $ virtualenv venv virtualenv venv will create a folder in the current directory which will contain the Python executable files, and a copy of the pip library which you can use to install other packages. This creates a copy of Python in whichever directory you ran the command in, placing it in a folder named venv. You can also use a Python interpreter of your choice. $ virtualenv -p /usr/bin/python2.7 venv This will use the Python interpreter in /usr/bin/python2.7 To begin using the virtual environment, it needs to be activated: $ source venv/bin/activate The name of the current virtual environment will now appear on the left of the prompt (e.g. Install packages as usual, for example: Other Notes $ pip freeze > requirements.txt

Online Python Tutor - Learn programming by visualizing code execution

Python programming

For Beginners
Welcome! Are you completely new to programming? If not then we presume you will be looking for information about why and how to get started with Python. Installing Python is generally easy, and nowadays many Linux and UNIX distributions include a recent Python. If you want to know whether a particular application, or a library with particular functionality, is available in Python there are a number of possible sources of information. If you have a question, it's a good idea to try the FAQ, which answers the most commonly asked questions about Python. If you want to help to develop Python, take a look at the developer area for further information.

Idiomatic Python: EAFP versus LBYL | Python Engineering at Microsoft
One idiomatic practice in Python that often surprises people coming from programming languages where exceptions are considered, well, exceptional, is EAFP: “it’s easier to ask for forgiveness than permission”. Quickly, EAFP means that you should just do what you expect to work and if an exception might be thrown from the operation then catch it and deal with that fact. What people are traditionally used to is LBYL: “look before you leap”. Compared to EAFP, LBYL is when you first check whether something will succeed and only proceed if you know it will work. If this all doesn’t make sense from the prose alone, don’t worry as code will make this obvious. if "key" in dict_: value += dict_["key"] This prevents a KeyError exception from being raised which seems logical. But what if the key is typically in the dictionary or shouldn’t be considered in any way exceptional? try: value += dict_["key"] except KeyError: pass Reading this code, what does it tell you?