[Python-Dev] other "magic strings" issues

Michael Hudson mwh at python.net
Mon Nov 10 05:38:05 EST 2003

Alex Martelli <aleaxit at yahoo.com> writes:

> From Barry's discussion of the problem of "magic strings" as arguments to 
> .encode / .decode , I was reminded of a blog entry,
> 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.

I think I prefer Guido's idea that when a function argument is almost
always constant you should really have two functions and /F's (?)
idea that there should be a 'textfile' function:

    textfile(path[, mode='r'[, encoding='ascii']]) -> file object

or similar.


  Need to Know is usually an interesting UK digest of things that
  happened last week or might happen next week. [...] This week,
  nothing happened, and we don't care.
                           -- NTK Now, 2000-12-29, http://www.ntk.net/

More information about the Python-Dev mailing list