background preloader

Hidden features of Python

Hidden features of Python
They're the magic behind a whole bunch of core Python features. When you use dotted access to look up a member (eg, x.y), Python first looks for the member in the instance dictionary. If it's not found, it looks for it in the class dictionary. If it finds it in the class dictionary, and the object implements the descriptor protocol, instead of just returning it, Python executes it. A descriptor is any class that implements the __get__, __set__, or __delete__ methods. Here's how you'd implement your own (read-only) version of property using descriptors: class Property(object): def __init__(self, fget): self.fget = fget def __get__(self, obj, type): if obj is None: return self return self.fget(obj) and you'd use it just like the built-in property(): class MyClass(object): @Property def foo(self): return "Foo!" Descriptors are used in Python to implement properties, bound methods, static methods, class methods and slots, amongst other things.

http://stackoverflow.com/questions/101268/hidden-features-of-python

PIL The Python Imaging Library (PIL) adds image processing capabilities to your Python interpreter. This library supports many file formats, and provides powerful image processing and graphics capabilities. Status The current free version is PIL 1.1.7. This release supports Python 1.5.2 and newer, including 2.5 and 2.6. A version for 3.X will be released later. JythonFaq/GeneralInfo - JythonWiki JythonFaq What is Jython? Jython is the successor to JPython. The Jython project was created in accordance with the CNRI JPython 1.1.x license, in order to ensure the continued existence and development of this important piece of Python software.

Tornado Web Server Tornado is a Python web framework and asynchronous networking library, originally developed at FriendFeed. By using non-blocking network I/O, Tornado can scale to tens of thousands of open connections, making it ideal for long polling, WebSockets, and other applications that require a long-lived connection to each user. Upgrade notes blist WhyJython - JythonWiki Jython, lest you do not know of it, is the most compelling weapon the Java platform has for its survival into the 21st century - SeanMcGrath Why Jython There are numerous alternative languages implemented for the Java VM. The following features help to separate Jython from the rest: Dynamic compilation to Java bytecodes - leads to highest possible performance without sacrificing interactivity. Ability to extend existing Java classes in Jython - allows effective use of abstract classes.

UserGuide - JythonWiki Intro For a look at the Jython internal API see the generated JavaDoc documentation. General Python Documentation Package Index : Isomyr 0.1 A Python Isometric Game Engine. <><> I S O M Y R <> A Python Isometric Game Engine i-so-myr: (n) Any of one or more scenes with the same measurements in foreground and background, that have different properties and can exist in any of several game worlds for a measurable period of time. Isomyr is an isometric game engine based on Pygame, and written in Python. Efficient String Concatenation in Python There is a Russian translation of this article, kindly provided by Artyom Scorecky (tonnzor). An assessment of the performance of several methods Introduction Building long strings in the Python progamming language can sometimes result in very slow running code. In this article I investigate the computational performance of various string concatenation methods.

Singleton? We don't need no stinkin' singleton: the Borg design pattern The 'Singleton' DP is all about ensuring that just one instance of a certain class is ever created. It has a catchy name and is thus enormously popular, but it's NOT a good idea -- it displays different sorts of problems in different object-models. What we should really WANT, typically, is to let as many instances be created as necessary, BUT all with shared state. Who cares about identity -- it's state (and behavior) we care about! You can ensure this in many ways in Python, but the Borg design pattern is almost always best. Since the self.

Python en:Exceptions - Notes You have seen how you can reuse code in your program by defining functions once. What if you wanted to reuse a number of functions in other programs that you write? As you might have guessed, the answer is modules.

Related: