Post thumbnail of Python memory management
19 May 2010
Continue reading Python memory management

Python memory management

Object creation and deletion is handled for you, but have you ever thought about how it works, when is memory freed, etc.? Think of everything in python as an object. Even something as simple as this, and since’s its a string, you can invoke any string method. When you lose access to some object, that memory is freed on its own. If you assign a string to a variable, you will find the memory locations are the same. Calling __del__ only removes access to the object from the local or global namespace. It does not mean the memory location has been freed.

Post thumbnail of Convert wordpress xml export file into a python dictionary
3 May 2010
Continue reading Convert wordpress xml export file into a python dictionary

Convert wordpress xml export file into a python dictionary

Requires web2py which includes Common shortcuts, Widgets, py2jquery module, Database store configuration settings, Class based menu builder, syntax highlighting, Output compression, and more.

Post thumbnail of Generate python code from Glade XML files
22 April 2010
Continue reading Generate python code from Glade XML files

Generate python code from Glade XML files

Why can’t I find a code generator that works? Tepache is a code sketcher for python that uses pygtk and glade, but it is broken and it looks like it hasn’t been updated since July 2005 anyway. Gladex was broken out of the box. Autocode does not like my glade and the documentation is limited.

Post thumbnail of Split a dictionary into two lists or vice versa in Python
16 April 2010
Continue reading Split a dictionary into two lists or vice versa in Python

Split a dictionary into two lists or vice versa in Python

Sometimes a dictionary is nice for keeping things simple. You can directly access any value by looking at the key. But perhaps you need to split the dictionary up into two lists. Or go the other way; turn two related lists into a key-value dictionary.

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.

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