background preloader

Python Module of the Week

Python Module of the Week

Understanding Python decorators BeginnersGuide/Programmers This is a Wiki page. Users with edit rights can edit it. You are, therefore, free to (in fact, encouraged to) add details of material that other Python users will find useful. It is not an advertising page and is here to serve the whole Python community. A beginner-friendly Python tutorial that starts with the absolute basics but also covers more advanced stuff like Python software deployment.

How to Think Like a Computer Scientist — How to Think Like a Computer Scientist: Learning with Python v2nd Edition documentation Navigation How to Think Like a Computer Scientist¶ Learning with Python¶ 2nd Edition (Using Python 2.x) by Jeffrey Elkner, Allen B. Downey, and Chris Meyers Last Updated: 21 April 2012 Copyright NoticeForewordPrefaceContributor ListChapter 1 The way of the programChapter 2 Variables, expressions, and statementsChapter 3 FunctionsChapter 4 ConditionalsChapter 5 Fruitful functionsChapter 6 IterationChapter 7 StringsChapter 8 Case Study: CatchChapter 9 ListsChapter 10 Modules and filesChapter 11 Recursion and exceptionsChapter 12 DictionariesChapter 13 Classes and objectsChapter 14 Classes and functionsChapter 15 Classes and methodsChapter 16 Sets of ObjectsChapter 17 InheritanceChapter 18 Linked ListsChapter 19 StacksChapter 20 QueuesChapter 21 TreesAppendix A DebuggingAppendix B GASPAppendix c Configuring Ubuntu for Python DevelopmentAppendix D Customizing and Contributing to the BookGNU Free Document License Search Page © Copyright 2010, Jeffrey Elkner, Allen B.

Dive Into Python 3 Dive Into Python Code Like a Pythonista: Idiomatic Python 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. My credentials: I am a resident of Montreal,father of two great kids, husband of one special woman,a full-time Python programmer,author of the Docutils project and reStructuredText,an editor of the Python Enhancement Proposals (or PEPs),an organizer of PyCon 2007, and chair of PyCon 2008,a member of the Python Software Foundation,a Director of the Foundation for the past year, and its Secretary. In the tutorial I presented at PyCon 2006 (called Text & Data Processing), I was surprised at the reaction to some techniques I used that I had thought were common knowledge. Many of you will have seen some of these techniques and idioms before. These are the guiding principles of Python, but are open to interpretation. import this

TimeComplexity This page documents the time-complexity (aka "Big O" or "Big Oh") of various operations in current CPython. Other Python implementations (or older or still-under development versions of CPython) may have slightly different performance characteristics. However, it is generally safe to assume that they are not slower by more than a factor of O(log n). Generally, 'n' is the number of elements currently in the container. 'k' is either the value of a parameter or the number of elements in the parameter. The Average Case assumes parameters generated uniformly at random. Internally, a list is represented as an array; the largest costs come from growing beyond the current allocation size (because everything must move), or from inserting or deleting somewhere near the beginning (because everything after that must move). A deque (double-ended queue) is represented internally as a doubly linked list. See dict -- the implementation is intentionally very similar.

The Python Property Builtin So I'm going to start writing every day. Hold me to that, please. Today I'm writing about one little corner of Python, the property function. I used a question that involved property as one of the interview questions during a recent developer search, and I found about a 50-50 split of people who knew about it, and those who didn't, and without much correlation to how much Python experience the developer had. I'm going to show basic usage, and then a couple ways to abuse it. Basic Usage class Person(object): def __init__(self, first_name, last_name): # pretty straightforward initialization, just set a couple # attributes self.first_name = first_name self.last_name = last_name def get_full_name(self): return "%s %s" % (self.first_name, self.last_name) full_name = property(get_full_name) And how it works in an interactive session: >>> me = Person("Adam", "Gomaa") >>> me.get_full_name() 'Adam Gomaa' >>> me.full_name 'Adam Gomaa' Why? Now why would you want to do this? Decorator Tricks and so on.

Related: