You can use regular expressions in python by using the “re” module. Both patterns and strings to be searched can be Unicode strings as well as 8-bit strings. Most of the regex module functions don’t force you to compile a regex object first, which I rarely do. You can easily use regular expressions by placing them inside python’s raw string notation using apostrophes.
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.
Here’s a way to use getopt to handle arguments when creating command line applications. It works quite well with the standard help (–help or -h) by showing usage when bad arguments are passed.
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.
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.”
I like it. It’s so simple and flexible. Define it with none, then assign sys.argv in place of argv.
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.
After your done building your wx objects and you’re ready to show it and call MainLoop(), wrap your main loop where you actually instantiate your gui objects in try/accept statements so that you can really catch any errors by calling the “show_errors()” function to launch a new message window where the errors will get displayed. This lets you catch errors before your whole program dies (causing errors to get lost).
Tail a file in Python
def tail( f, window=20 ):
f.seek( 0, 2 )
bytes= f.tell()
size= window
block= -1
while size > 0 and bytes+block*1024 > 0:
…
I didn’t find a glade template for this one, but I’m starting to lean away from using a gui builder. It seems more trouble than it’s worth.