background preloader

30 Python Language Features and Tricks You May Not Know About

30 Python Language Features and Tricks You May Not Know About
1 Introduction Since I started learning Python, I decided to maintain an often visited list of "tricks". Any time I saw a piece of code (in an example, on Stack Overflow, in open source software, etc.) that made me think "Cool! I didn't know you could do that!" I experimented with it until I understood it and then added it to the list. This post is part of that list, after some cleaning up. Each trick or language feature is demonstrated only through examples, with no explanation. The list is very roughly ordered by difficulty, with the easier and more commonly known language features and tricks appearing first. A table of contents is given at the end. Update - April 9th, 2014 As you can see the article has been growing with currently 38 items in it, mostly thanks to comments from readers. Update - March 14th, 2014 Roy Keyes made a great suggestion of turning this article into a GitHub repository to allow readers to make improvements or additions through pull requests. 1.1 Unpacking

http://sahandsaba.com/thirty-python-language-features-and-tricks-you-may-not-know.html

Related:  LanguagesHelp and TipsPythonPy:TipsPython

Cobra (programming language) Cobra is an open-source project; it was released under the MIT License on February 29, 2008.[7][8] Updates are posted to the Cobra news forum with progress on features, fixes, documentation and related projects since the last update.[9] Object-oriented Understanding Python Decorators in 12 Easy Steps! Ok, perhaps I jest. As a Python instructor, understanding decorators is a topic I find students consistently struggle with upon first exposure. That’s because decorators are hard to understand! Getting decorators requires understanding several functional programming concepts as well as feeling comfortable with some unique features of Python’s function definition and function calling syntax. Scientific Analysis in Python Python based scientific analysis cookbook James Battat Created: October 3, 2006 Last Modified: July 12, 2010 I find Python very user-friendly. Therefore I often reach for it when tasked to solve small or large scripting problems. I have been rather frustrated, though, with the level of support for scientific analysis packages. With scipy and matplotlib, of course, the tools are all there and success is just around the corner... But if you're like me and you're at a loss when trying to do something in Python because you're used to using other languages (IDL) for scientific analysis then you may find this page useful.

Keeping It Classless If you're new here, you may want to subscribe to my RSS feed, or follow me on Twitter! That way you can stay up to date with all Keeping It Classless posts! It’s been really interesting to see the industry in an all-out zerg rush to adopt Python as a skill-set.

Turning the Raspberry Pi into a SMS Center using Python – My Blog As I described already in another article – Running the Raspberry Pi on Solar Power it is pretty easy to run the Raspberry Pi on solar energy. This fact combined with the small form factor of the Pi makes it extremely portable platform. In one of my projects I will leave the Raspberry Pi working in a distant rural area with no wired or wifi connection.

Hacking Thought Blog: My Opinionated Guide To Go (golang) tl;dr: The modern software environment with internal and external services has become a distributed system that is constantly changing (continuous deployment). A simpler language based on the unix philosophy(ies) that supports concurrency, expects errors, leverages the internet and ships with great tools is a wonderful thing! Unleash the Unix! Talking with dev ops people these days I get the sense that stacks look roughly like this: Decorator Design Pattern Intent Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.Client-specified embellishment of a core object by recursively wrapping it.Wrapping a gift, putting it in a box, and wrapping the box. Problem You want to add behavior or state to individual objects at run-time. Inheritance is not feasible because it is static and applies to an entire class.

Linear regression with pylab In order to compliment my linear regression in google docs post (and because I keep forgetting how to do it), here is a quick and dirty guide to linear regression using python and pylab. First some notes. One, there is some good info on this online (how else do you think I find this stuff?). Here is a great link: SciPy Cookbook on linear regression. Second, remember that I do things the ‘hard way’ sometimes.

Related:  Python