Post thumbnail of How to make a dictionary of dictionaries with Python
18 October 2011
Continue reading How to make a dictionary of dictionaries with Python

How to make a dictionary of dictionaries with Python

Create a simple class of dictionaries to make a dictionary of dictionaries. No need for generators, iterators or lambdas. Use a deck of cards for example.

Post thumbnail of Get the hostname of a system in python
7 October 2011
Continue reading Get the hostname of a system in python

Get the hostname of a system in python

There are multiple ways to do it. Some are platform dependent.The best way is probably through socket, but you can use platform and os too.

Post thumbnail of Make stock gtk icons from your own images and pixbufs
19 September 2011
Continue reading Make stock gtk icons from your own images and pixbufs

Make stock gtk icons from your own images and pixbufs

If you want to set a cell to a pixmap, ok no problem, but what about setting individual liststore values to a pixmap? You can’t do it directly unless you’re using a gtk.STOCK_ image. Here’s a way around that little problem.

Post thumbnail of Python: two-way thread communication made simple
13 September 2011
Continue reading Python: two-way thread communication made simple

Python: two-way thread communication made simple

You don’t need heavyweight communication layers for very simple message passing between threads in python. It’s pretty simple to use pipes and implement your own thread class.

Post thumbnail of Hide a dialog without destroying - pygtk one-liner
2 September 2011
Continue reading Hide a dialog without destroying - pygtk one-liner

Hide a dialog without destroying - pygtk one-liner

If you like the standard window decorations and dont need/want to create your own buttons to handle custom events, closing a dialog without destroying it is a simple one-liner in pygtk. This is helpful when you have logic that replaces individual widgets inside a dialog and you don’t want to recreate the whole dialog.

Post thumbnail of isset() php function equivalent in python
20 June 2011
Continue reading isset() php function equivalent in python

isset() php function equivalent in python

If you need this, you’re probably doing it wrong. But if you really must check to see if a variable has been assigned yet, there’s nothing really stopping you. Here’s one way of implementing it.

Post thumbnail of Thread control in python - how to safely stop a thread
20 June 2011
Continue reading Thread control in python - how to safely stop a thread

Thread control in python - how to safely stop a thread

So you want to kill a thread… Dangerous. How about asking a thread to die instead? Of course it’s unsafe to just kill a thread dead in its tracks. What if the thread has some resource acquired or is controlling other threads itself? It’s much better to communicate with a thread and tell it to stop, then just wait for it to kill itself.

Post thumbnail of Simple AES Encryption Vault in python
9 June 2011
Continue reading Simple AES Encryption Vault in python

Simple AES Encryption Vault in python

I needed to encrypt some strings before sending them out over the network to another process and I don’t want to rely on another mechanism for handling the encryption, so here’s my simple AES encryption class. You can load plain text out of the vault by providing a cipher or save an encrypted message by supplying the plain text.

Post thumbnail of Python Easter Eggs
8 June 2011
Continue reading Python Easter Eggs

Python Easter Eggs

There are a few hidden easter eggs in python. So next time you fire up the python shell try to import hello and this. I wonder how many other hidden gems there are.

Post thumbnail of Printing variables in python with placeholders
6 May 2011
Continue reading Printing variables in python with placeholders

Printing variables in python with placeholders

Even if you’ve only dabbled with python for a minute or two, you’ve probably already figured out that you can print variables using placeholders. You might have tried concatenation too. However, did you know you can print using %s but with the variable names directly?

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