How to add duration info to a FLV file with the flvtool2 command

Very useful. Sometimes some flv conversion tools don’t include info that is vital for playback. In this case, the seekbar wouldn’t show up in the player until after playback finished. I’ll be testing to see if this resolves it but either way, this is good to know. The first hint was this post stating that [...]

Python array copy

I had heard about passing by reference vs. passing by value. Here is a case of passing by reference.
In [76]: a=[1,2]In [77]: b=aIn [78]: b.append(3)In [79]: aOut[79]: [1, 2, 3]
That’s not what I was looking for. I was hoping to get ‘b’ to be [1, 2, 3] leaving ‘a’ unchanged. Oops. It passed ‘a’ to [...]

Extract .bz2 on Linux

I am updating some python libs on my webfaction host. The python easy_setup isn’t working for this particular bit though which is unusual. It’s the first time it didn’t work. The reason? It seems it chokes on .bz2 archives. The one in particular is python-dateutil. Fortunately a quick wget later and it’s downloaded. On OS [...]

Exporting a web2py table in XML

I recently wrote about exporting a Django database to xml. As a courtesy, Massimo, creator of web2py, put together a great little example for web2py
exporting in XML - web2py Web Framework | Google Groups

def export_xml(rows):
idx=range(len(rows.colnames))
colnames=[item.replace('.','_') for item in rows.colnames]
records=[]
[...]

Predefined variables with lambda variables

This little line right here solved a problem. How do you dynamically assign a function to a variable to be invoked later but you need it to have a preset value? Define it when you assign it. I just didn’t know you could do that with lambda functions. Cool! This was used to update my [...]

More list comprehensions

This may get mangled with ScribeFire. It was, and fixed in Zoundry’s Raven.
It’s a great example though of taking a list and changing it with a list comprehension. That last one qualifies as a one liner.
3.6. Mapping Lists (from Dive into Python)
>>> params = {”server”:”mpilgrim”, “database”:”master”, “uid”:”sa”, “pwd”:”secret”} >>> params.items() [('server', 'mpilgrim'), ('uid', [...]

Python Decorate Sort Undecorate Pattern

How do you srt a dict of items in one line?
Pythoneer » A functional task, I am sure

d = {4: 6, 12: 4, 14: 14, 18: 16, 32: 6, 33: 24, 40: 27, 41: 6, 44: 25, 106: 2}sorted(d.items(), key=itemgetter(1))

You can also do something similar for strings of text:
Python DSU [...]