Help and Tips
Get flash to fully experience Pearltrees
I've been programming in python for a few years now, and I'm still often amazed by how clear and DRY well written Python code can be. There are many small tips and tricks I've learned over time, mostly by reading the code of popular open source projects, such as Django , Flask , Requests and others. Here are a few things I've picked up that are sometimes overlooked, but can really help with everyday work. 1.
Python comes with a large number of built-in functions, operators and keywords. They make working with data structures and built-in types very easy, but usually when we define our own data types (classes) we also tend to come up with our own ways to manipulate and consume our data. One of the nice things in python, is that we don't have to. We can use "underscore methods" to make our classes compatible with the built-in functions and operators. This makes our code easier to use and does a better job of hiding our nasty, complex implementation from the user.
Finding the name of the program from which a Python module is running can be trickier than it would seem at first, and investigating the reasons led to some interesting experiments. A couple of weeks ago at the OpenStack Folsom Summit, Mark McClain pointed out an interesting code snippet he had discovered in the Nova sources : nova/utils.py: 339 script_dir = os . path . dirname ( inspect . stack ()[ - 1 ][ 1 ])
Created 24 April 2012, last updated 19 March 2013 This is a presentation I gave at PyCon 2013. You can read the slides and text on this page, or open the actual presentation in your browser (use right and left arrows to advance the slides), or watch the video: A talk for PyCon 2013.
Python Community Sites
This document aims to give an overview of Windows-specific behaviour you should know about when using Python on Microsoft Windows. 3.1. Installing Python
This document discusses some of the common pitfalls in getting python scripts running under Windows, with an emphasis on enabling python cgi scripts through Windows Apache. On the PYTHONPATH Finding python.exe
pycon 2010 atlanta presents the mighty dictionary (#55) by brandon craig rhodes video produced by carl karsten & a team in conjunction with the psf and support from: [sauce ___ ijwbitz you too can support the psf: http://www.python.org/psf/donations/ 9: how can python lists access every one of their items with equal speed? timeit(’mylist[o]’, my1ist =  * 9000’) /1 — -> 0.053692102432250977 ‘50 ns per getitern timeit(’mylist’, ‘mylist =  * 90001) # -- 0.051i60ø276947ø2148 —50 ns per getitem 9: how can python lists access every one of their items with equal speed?
Python’s handling of default parameter values is one of a few things that tends to trip up most new Python programmers (but usually only once). What causes the confusion is the behaviour you get when you use a “mutable” object as a default value; that is, a value that can be modified in place, like a list or a dictionary. An example: >>> def function(data=): ... data.append(1) ... return data ... >>> function()  >>> function() [1, 1] >>> function() [1, 1, 1] As you can see, the list keeps getting longer and longer. If you look at the list identity, you’ll see that the function keeps returning the same object:
In this interactive tutorial, we'll cover many essential Python idioms and techniques in depth, adding immediately useful tools to your belt. There are 3 versions of this presentation: ©2006-2008, licensed under a Creative Commons Attribution/Share-Alike (BY-SA) license .