Thursday, May 29th, 2008 10:49 PM
Want to show something on your machine to someone over the web? Don’t copy it or upload it somewhere. Just run “webshare” and the current directory and everything beneath it will be served from a new web server listening on port 8000. When your pal is finished, hit control-c.
python -c "import SimpleHTTPServer;SimpleHTTPServer.test()"
For a slightly more advanced version of this server, see this article(Warning: German Article - but code is self explaining)
No Comments »
Sunday, October 14th, 2007 10:52 PM
Creating a toolbar using GTK Python. There is an old method - but this example shows a better method of creating a toolbar using pygtk.
toolbar = gtk.Toolbar()
toolbar.set_style(gtk.TOOLBAR_BOTH)
toolbar_item = gtk.ToolButton("Quit")
toolbar_item.set_stock_id(gtk.STOCK_QUIT)
toolbar_item.connect("clicked", exit)
toolbar_item.show()
toolbar.insert(toolbar_item, -1)
toolbar.show()
No Comments »
Tuesday, October 9th, 2007 11:00 PM
A Python function to return readable size using the given size(KB)
# Returns a more readable format of the given data. For example, getReadableSize(1024) returns "1 MB"
def getReadableSize(size):
unit = "KB"
size = float(size)
final = size
if(size >= 1024):
unit = "MB"
final= "%.02f" % (size / 1024)
size = (size / 1024)
if(size >= 1024):
unit = "GB"
final= "%.02f" % (size / 1024)
size = (size / 1024)
return str(final) + " " + unit
[tags][/tags]
No Comments »
Sunday, October 7th, 2007 11:38 PM
Execute a command and get its results using python in Linux
import commands
result = commands.getoutput("ls")
No Comments »