thread specific sys.stdout?
Peter Hansen
peter at engcorp.com
Wed Sep 15 19:05:44 EDT 2004
aurora wrote:
> On Wed, 15 Sep 2004 23:14:47 +0200, Diez B. Roggisch
>> class ThreadPrinter:
>> def __init__(self):
>> _.fhs = {}
>>
>> def write(self, value):
>> f = _.fhs.get(threading.currentThread(),
....
> Thanks this is a nice idea. I hope Python would actually support the
> '_' syntax. The self really reduce readablity, especially if you have
> several of them in one line.
It does! One just has to be consistent within each function.
Diez changed the code from something like this:
def __init__(_):
_.fhs = {}
def write(_, value):
f = _.fhs.get(threading.currentThread(),
...
Some would argue that this is actually less readable, however,
since it uses punctuation instead of a word. If nothing else,
you run into a bit of a conflict between your own technique,
with "_", and the vast majority of the rest of the Python world,
which uses "self" exclusively, leading to situations like this
one...
(I think if I had a routine that really heavily used self,
to the obvious detriment of readability, and it wasn't clear
how else to improve it, I would use a local assignment at
the top to make a shorter name, perhaps "s", or even "_" --
but I wouldn't use the possibility of such a thing as a
justification for using _ everywhere.)
-Peter
More information about the Python-list
mailing list