On Jan 27, 7:33 pm, Ben Finney <[EMAIL PROTECTED]>
wrote:
> "Russ P." <[EMAIL PROTECTED]> writes:
> > On Jan 27, 5:13 pm, Wildemar Wildenburger
> > <[EMAIL PROTECTED]> wrote:
> > > class Server(object):
> > >      def __init__(self, self.host, self.port,
> > >                   self.protocol, self.bufsize, self.timeout):
> > >          pass
>
> > > ?
>
> > That makes sense to me.
>
> Not to me. 'self' is a name that doesn't exist until *after* that
> 'def' statement is completed; in any other statement, that would mean
> 'self.foo' in the same statement would raise a NameError.
>
> Special-casing it for a function declaration complicates the language
> for little gain: the rules of what is valid when become more
> complicated. Special cases aren't special enough to break the rules.
>
> --
>  \        "I took a course in speed waiting. Now I can wait an hour in |
>   `\                              only ten minutes."  -- Steven Wright |
> _o__)                                                                  |
> Ben Finney

OK, then how about a special function that could be called from inside
the constructor (or anywhere else for that matter) to initialize a
list of data members. For example,

self.__set__(host, port, protocol, bufsize,
    timeout)

This would be equivalent to

self.host = host
self.port = port
# etc.

I'm not sure if that is technically feasible, but it would cut down on
repetition of names.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to