Post thumbnail of Show methods for any object in Python
15 April 2010
Continue reading Show methods for any object in Python

Show methods for any object in Python

This is pretty simple, but it took me a few years before I ran into this. It’s just not covered in the basic documentation. Forget auto completion for a moment and let’s just show how to display the methods available for an object, any object. To show methods for any object, use object.__dict__ and object.__dict__.keys()

Post thumbnail of How to reverse a list or string in Python
14 April 2010
Continue reading How to reverse a list or string in Python

How to reverse a list or string in Python

So easy, and it works with lists too. Won’t work with dictionaries but it should work with any hash-able type.

Post thumbnail of Installing Pylons and BlastOff - YUM alternative to easy-install
23 February 2010
Continue reading Installing Pylons and BlastOff - YUM alternative to easy-install

Installing Pylons and BlastOff - YUM alternative to easy-install

The Pylons web framework is aimed at making webapps and large programmatic website development in Python easy. Pylons combines the very best ideas from the worlds of Ruby, Python and Perl, providing a structured but extremely flexible Python web framework. BlastOff is a Pylons application template providing a working site skeleton configured with SQLAlchemy, mako, repoze.who, ToscaWidgets, TurboMail, and WebFlash.

Post thumbnail of Python Regular Expression Syntax
14 January 2010
Continue reading Python Regular Expression Syntax

Python Regular Expression Syntax

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.

Post thumbnail of subprocess.popen and static define in Python
13 January 2010
Continue reading subprocess.popen and static define in 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.

Post thumbnail of Store and access passwords safely with python’s keyring
22 December 2009
Continue reading Store and access passwords safely with python’s keyring

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.

Post thumbnail of Just another why Python rules article
21 December 2009
Continue reading Just another why Python rules article

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.”

Post thumbnail of Function arguments optional in python
17 December 2009
Continue reading Function arguments optional in python

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.

Post thumbnail of Python: Use subprocess to easily catch return values
13 November 2009
Continue reading Python: Use subprocess to easily catch return values

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.

Post thumbnail of Tail a file in Python
20 October 2009
Continue reading Tail a file in Python

Tail a file in Python

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:

 Page 3 of 5 « 1  2  3  4  5 »
Powered by Wordpress   |   Lunated designed by ZenVerse