July 17, 2003
Python Warts updated

Andrew Kuchling has updated his Python Warts page, to take recent changes to Python into account.

There are a couple of things in there that I really don't see as warts at all. Raw strings, for example, seem to me to be a a fairly elegant was of solving the escaping problem.

The explicit self. requirement is something I find helpful. It makes it obvious whether you are dealing with an instance variable or a local one. In Java, I always use the this. prefix.

The .join() string method? What can I say? I've just got so used to it now that I wouldn't have it any other way. Besides, the martellibot has shown why join() is best implemented as a string method.

What's missing? Well, as of 2.3, you still need the string module for several constants, even though (almost all) the functions are available as string methods. But I gather that by version 3.0, the string module will be deprecated. So by then, the constants will have to have been put somewhere else - probably they'll be attributes of the built-in str object.

Assuming that the str object does grow attributes, the idea could be extended. When you open a file using the built-in file() object, you need to pass it a bunch of mode flags. These you pass as strings, which I find ugly - another wart, IMHO. These could easily become attributes of file. So, instead of:

myFile = file(filename, 'rb')

, you could do:

myFile = file(filename, file.READ + file.BINARY)

Longer, yes, but easier to remember and to read, I think.

Opening files isn't the only place where you use fairly arbitrary characters like this - the struct module springs to mind, where you have 'format characters'. These should defined as constants by the module, I think.

Oh yes, one other thing. os.path.walk must die. And I see it's on its way out now - the Timbot's new os.walk generator has made it into 2.3, and a thing of beauty it is too.

Posted to Python by Simon Brunning at July 17, 2003 02:34 PM
Comments
Post a comment
Name:


Email Address:


URL:



Comments:


Remember info?