Browsing articles tagged with " Tricks"
Jun
24
24
# Override decorator
While working with pyglet one day, I made the mistake of subclassing the window class and overriding the __init__ method, which prevented the window from showing. To fix this, it’s easy enough to add a call to super(Window, self).__init__(*args, **kwargs), but I went a different route. Here’s a decorator called override that puts it in for you:
def override(function):
def wrapper(instance, *args, **kwargs):
super(instance.__class__, instance).__init__(*args, **kwargs)
return function(instance, *args, **kwargs)
return wrapper
To use it, simply use the decorator notation in a subclassed method:
class MyWindow(pyglet.window.Window):
@override
def __init__(self, *args, **kwargs):
# code goes here, no need to call super!
Feb
25
25
# Python Dictionary Coolness
Lately I’ve been working with dictionaries, specifically as a device for storing settings. I ran into a little annoyance and thought of programming a little routine to take care of it. Come to find out, Python already has such a routine built into the dictionary class. Read on to find out more.
Tags
Apple
Business
Critique
css
dell
Design
Design Patterns
facebook
firefox
Gmail
google
Hotmail
Interface
javascript
laptop
Links
Linux
Mac
Microsoft
netbook
OpenGL
OS
Philosophy
PHP
Podcast
Programming
Pyglet
Python
Pythonic Programming
Review
Search
services
Symfony
Time Management
Tutorial
Tutorials
Twitter
ubiquity
Ubuntu
update
Version Control
web design
Windows
Windows 7
Windows Mobile

