Interior Octopus

April 14, 2005
25 comments Photos

Interior Octopus Someone added a test issue on the Demo issuetracker with an amazing file attachment.

I have no idea where it comes from and the person who uploaded it might have left an email address that doesn't work. I've tried emailing this person in hope of more info.

Imagine that some rich person has this as interior design in their house. (the person must be rich if he/she can afford a piece of art to consume so much space in the house)

Find print statements in Python code

April 12, 2005
6 comments Python, Linux

Do you, like me, use the powerful print function to debug your Python code? Do you, like me, sometimes forget to remove lines with print and ship this out to less development-like environments? Do you, like I did, need a way to check for forgotten print statements?

I've written a dumb-simple script that scans through a directory for print statements. It uses a recursive grep command so this won't work for you hopeless Windows people :)

Download it and put it in your ~/bin (you might want to read it through) then all you have to do is to run it against a directory where there are lots of .py files:


$ find_print_statements.py ~/dev/mypythonmodule

If it doesn't work perhaps you can patch it and let me know. This might not be for the faint-hearted. There might be serious security concerns unless you have full control over your users and su account. I take no responsibility if this script rm -fr / your hd.

Truncated! Read the rest by clicking the link below.

Your webpage in Lynx

April 8, 2005
0 comments Web development

Lynx is a web browser that is so basic in functionality that even Microsoft Internet Explorer is more userfriendly; sometimes. It's not graphical which means that you can run in on the command line of a computer where graphical applications aren't an option such as SSH access.

Another more important thing about Lynx is that it indicates how a blind person might see a website. (Remember, Google is blind) If you want to make a really accessible website that works universally you have to make sure it works in Lynx too. For non-Linux people it might not be so obvious how to install Lynx, and that's where LynxView comes in.

Here's what you see if you browse my website with Lynx and the IssueTrackerProduct.com

So if you're serious about your website please do make sure your site works reasonably well in LynxView.

Control comment spam

April 5, 2005
1 comment Python

Did you see my mentioning about addhrefs last week? addhrefs is a python module that turns a text full of URLs and email addresses into links. For example:


>>> from addhrefs import addhrefs
>>> print addhrefs("""Visit www.peterbe.com 
and email mail@peterbe.com""")
Visit <a href="https://www.peterbe.com">www.peterbe.com</a>
and email <a href="mailto:mail@peterbe.com">mail@peterbe.com</a>

Then I saw this instruction on google.com about Preventing comment spam They suggest you add a rel="nofollow" to links in your comments on your blog and with a bit of luck this will reduce the amount of comment spam you get on your blogs. So, how to do that?

Truncated! Read the rest by clicking the link below.

Python Cookbook arrived

April 5, 2005
2 comments Books

python cookbook I got my copy of the Python Cookbook today. This book might have been available in the US for some time but I had it preordered here in the UK. So for all fellow UK Python people who have been waiting like myself, just wanted to let you know that now it's avaible.

callable Python objects

April 2, 2005
8 comments Python

Python gurus are going to laugh at me for this one but I learnt it today; how to check if an object is callable. Before this I thought I was clever with this:


>>> def foo(): return "s"
>>> hasattr(foo, '__call__')
True
>>> hasattr(foo(), '__call__')
False

But there was an easier way. I discovered this by accident and looked it up in the documentation after. Use the builtin function called 'callable()':


>>> def foo(): return "s"
>>> callable(foo)
True
>>> callable(foo())
False

D'oh!

Ugly one-liner to debug an object in Zope

March 31, 2005
2 comments Zope

If you're a Zope developer like myself you will most likely have written code like this many times:


class MyProduct(...):
   def showName(self, nameobject):
       """ doc string """
       print dir(nameobject) # this is the example
       return nameobject.getName()

Namely that you use the dir() builtin function to inspect an object's attributes. It's a wonderful function that from what I've experienced only Python excels. (Apparently Bruce Eckels lists introspection as one of the best features of Python and he's a guru with Java and C++)

Truncated! Read the rest by clicking the link below.

Searching for the obvious

March 29, 2005
0 comments Wondering

Have you ever searched Google for something obvious like "news", "software" or "internet"? I have, but doing it felt very original.

Before reading on (unless it's too late) to guess what you'd find on the top spot of a Google search if you search for "news".

Ok, here are the results.

Truncated! Read the rest by clicking the link below.

Read in passwords with bash

March 25, 2005
37 comments Linux

This has taken me some time to figure out because I couldn't find anything on Google. I think the problem was that I didn't know what to look for.

If you have a bash script that asks the user to enter their username and password you use the read function in sh. But when you read in the password you don't want it to show on the screen what you're writing. Someone could be leaning over your shoulder. Python has a similar standard library module called getpass which works like this:


>>> from getpass import getpass
>>> p = getpass("Password please: ")
Password please: 
>>> print "Your password is", len(p), "characters long"
Your password is 5 characters long

That's fine if you do this via Python; but I needed to do it in one of my bash scripts. Here's how to do it:


#!/bin/bash
read -p "Username: " uname
stty -echo
read -p "Password: " passw; echo
stty echo

Now, hopefully this will help other people who get stuck with the same problem.