python
subprocess.popen and static define in Python
I like os’s subprocess.Popen() to run shell commands from within my Python code. I also like to define TRUE and FALSE to use as return values. Now I know what you’re thinking: there’s no such thing as ‘C’s #define in python because there’s no compiler to swap out of all your substitutions at compile time. However, it’s just as easy to achieve the same results.
Store and access passwords safely with python’s keyring
Python’s keyring lib supports Windows win32crypto, Mac OS X’s SXKeychain, KDE’s KWallet, Gnome’s keyring, and encrypted or unencrypted password files. When your application wants to store or fetch data from the keyring, it will just work.
Just another why Python rules article
It’s all about the design of the language and I agree with the author completely when he says, “Most languages have so much friction and awkwardness built into their design.”
Function arguments optional in python
I like it. It’s so simple and flexible. Define it with none, then assign sys.argv in place of argv.
Python: Use subprocess to easily catch return values
Run system commands or call a sub-process and assign the return value to a variable. This makes it easy to pass the error up to your processes parent.
Tail a file in Python
===Tail a file in Python===
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
def tail( f, window=20 ): f.seek( 0, 2 ) bytes= f.tell() size= window block= -1 while size > 0 and bytes+block*1024 > 0: f.seek( block*1024, 2 ) data= f.read( 1024 ) linesFound= data.count('\n') size -= linesFound block -= 1 f.seek( block*1024, 2 ) f.readline() lastBlocks= list( f.readlines() ) print lastBlocks[-window:] |
Focusing on the hard parts of wxPython – layout and events
I like wxPython a lot more than the other gui tooltkits i’ve tried. I’m finding it really easy to keep it from getting cluttered, and it’s easy to pick up and run with, but there’s some demo’s like this one below, that i’ve seen in various forms all over the place now, that I think are a waste of time. Why would you have a app that has nothing but a menu bar? You wouldn’t, so doesn’t it make sense to get the confusing parts of gui code out of the way? Namely, layout and events.