background preloader

Python

Facebook Twitter

Django

The Python Property Builtin. So I'm going to start writing every day.

The Python Property Builtin

Hold me to that, please. Today I'm writing about one little corner of Python, the property function. It's a builtin function, around since at least 2.2. 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. So I think it's one of those things that you only really use if you know about it - it's by no means essential, and you can go your whole Python career not knowing about it, but, well, as toolboxes go, this is a pretty nifty screwdriver. I'm going to show basic usage, and then a couple ways to abuse it. Basic Usage 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 Example: Django URLs. Python for Facebook - Welcome. TimeComplexity. This page documents the time-complexity (aka "Big O" or "Big Oh") of various operations in current CPython.

TimeComplexity

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. Python Module of the Week.

Testing&ContinousIntegration

Understanding Python decorators. BeginnersGuide/Programmers. Please Note This is a Wiki page.

BeginnersGuide/Programmers

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. Users who continually edit pages to give their own materials (particularly commercial materials) prominence, or spam the listing with multiple entries which point to resources with only slightly altered material, may subsequently find their editing rights disabled. Python for Programmers The tutorials on this page are aimed at people who have previous experience with other programming languages (C, Perl, Lisp, Visual Basic, etc.).

Books, Websites, Tutorials (non-interactive) Resources A beginner-friendly Python tutorial that starts with the absolute basics, but also covers more advanced stuff like Python software deployment. Interactive Tools and Lessons. 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.

How to Think Like a Computer Scientist — How to Think Like a Computer Scientist: Learning with Python v2nd Edition documentation

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.

Code Like a Pythonista: Idiomatic Python

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.