Lolrus.org
This is a header that goes on every page.Mapping Ordered Args to Keyword Args in Python
May 24, 2009 at 03:09 AM | categories: Color, Uncategorized | CommentIt's been a while, so I thought I'd start off slow with a little tidbit I busted out today.
Here's the problem:
Say I have
def foo(b, c):
...
and
def bar(a, b, c, *args, **kwargs):
...
and
def baz(*args, **kwargs):
...
And I want to write a decorator or something that intercepts the variable b before it hits the function.
How am I supposed to know which one is b when it's different positions in each function, or could even be a kwarg?
I have my decorator right here:
from decorator import decorator
@decorator
def lol_dec(fn, *args, **kwargs):
...
I figured the best solution would be moving the args that could be named intoto the kwargs. It took me a bit of digging until I came across the inspect module, but it worked, and can work for you.
from inspect import getargspec
def fudge_args(fn, args, kwargs):
#TODO once we all use 2.6 change it to following
#fn_args = getargspec(fn).args
fn_args = getargspec(fn)[0]
new_kwargs = dict(zip(fn_args, args))
new_kwargs.update(kwargs)
return args[len(fn_args):], new_kwargs
It's as easy as that. We just take the list of args from the ArgSpec, zip it up with the list of ordered arguments (args). Add them to a copy of kwargs. Note, we're only returning args that were left over after the zip.
It's used like so:
@decorator
def lol_dec(fn, *args, **kwargs):
args, kwargs = fudge_args(fn, args, kwargs)
kwargs['b'] = kwargs['b'] * 3
return fn(*args, **kwargs)
Color Problems Solved
August 21, 2007 at 02:01 AM | categories: Color | CommentI re-exported my files as JPEGs with sRGB ICC profiles embedded. Everything worked fine in FF and IE, but in Safari it was still broken. I think that Apple would have Safari handle colors properly.
I did some investigation and here's what I found out. Firefox is NOT color managed (rumor has it that in 3.0 it will be). I was able to get hex colors in the page such as backgrounds and fonts match the hex colors in my image by turning ALL of the ICC color management off and not embedding it.
What a pain. Turns out that no color management is the most consistent. I'm still confused why the colors on the page weren't the same as the ones in the image when the image had an sRGB profile embedded in it, and web colors by default are supposed to be in sRGB color space.
*grumble*
Color Management Nightmare
August 20, 2007 at 02:54 PM | categories: Color, Uncategorized | CommentSo I've been working on a new layout for my blog, using PNGs and divs and such. Everything was going along nice and well, until I tried viewing the page in Safari . Bamf, all my colors were off.
I think the web needs a replacement for PNGs, or at least PNGs with embedded color profiles.
My monitor is calibrated and everything.
Take a look:
This isn't really a problem with either browser per se, but just an issue with color management in general. I think I will have to stick to jpegs for this because you can embed an ICC profile in them.
Updates to come with solutions.
[edit] Apparently, it has a third appearance in IE. So, it seems like the answers are headed towards PNGs are broken. It might be time for a new image format that contains an alpha channel.