On 22 Aug 2005 02:48:24 -0700, Paul Rubin <http://[EMAIL PROTECTED]> wrote:
>"Greg McIntyre" <[EMAIL PROTECTED]> writes:
>> while c = f.read(1):
>> # ...
>>
>> I couldn't find any general PEPs along these lines, only specific ones
>> (e.g. 308 re. an if-then-else expression).
>
>I often end up doing something like this:
>
> class foo:
> def set(self, x):
> self.x = x
> return x
> c = foo()
>
> while c.set(f.read(1)):
> # do stuff with c.x
>
>In that file example, it's too much nuisance, but when you're
>comparing some input against a series of regexps and you'd otherwise
>need a multi-line construction for each one, this method comes in
>quite handy.
if you use def __call__ instead of def set, you can also simplify the
subsequent spelling e.g,
while c(f.read(1)):
# do stuff with c.x
though something more menmonic than c might be desirable in that case.
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list