[Python-Dev] other "magic strings" issues

Guido van Rossum guido at python.org
Fri Nov 7 12:05:12 EST 2003

> http://www.brunningonline.net/simon/blog/archives/000803.html
> which mentions another case of "magic strings" that might perhaps be
> (optionally but suggestedly) changed into more-readable attributes (in
> this case, clearly attributes of the 'file' type): mode arguments to 'file'
> calls.  Simon Brunning, the author of that blog entry, argues that
> myFile = file(filename, 'rb')
> (while of course we're going to keep accepting it forever) is not quite as 
> readable and maintainable as, e.g.:
> myFile = file(filename, file.READ + file.BINARY)
> Just curious -- what are everybody's feelings about that idea?  I'm
> about +0 on it, myself -- I doubt I'd remember to use it (too much C
> in my past...:-) but I see why others would prefer it.

Doesn't seem the right solution to me.  If I were to design an API
for this without reference to the C convention, I'd probably use
keyword arguments.

I outright disagree with Brunning's idea for the struct module.  More
verbose isn't always more readable or easier to remember.

> Another separate "attributes of types" issue raised by that same
> blog entry -- and that one does find me +1 -- is: isn't it time to
> make available as attributes of the str type object those few things
> that we still need to 'import string' for?  E.g., the maketrans
> function (and maybe we could even give it a better name as long as
> we're making it a str.something?)...

Yes, that would be good.  Is there anything besides maketrans() in the
string module worth saving?  (IMO letters and digits etc. are not --
you can use s.isletter() etc. for that.)

--Guido van Rossum (home page: http://www.python.org/~guido/)

More information about the Python-Dev mailing list