Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eweka.nl!lightspeed.eweka.nl!194.134.4.91.MISMATCH!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'exception': 0.03; 'syntax': 0.03; '*not*': 0.07; 'so?': 0.07; 'api': 0.09; "'.'": 0.09; 'determines': 0.09; 'identifier': 0.09; 'imports': 0.09; 'objects.': 0.09; 'referenced': 0.09; 'setattr,': 0.09; 'special,': 0.09; 'subclass': 0.09; 'programmer': 0.11; 'library': 0.15; '"module"': 0.16; "':'": 0.16; 'bind': 0.16; 'bytecode': 0.16; 'collections.': 0.16; 'enough.': 0.16; 'foolishly': 0.16; 'iterated': 0.16; 'module?': 0.16; 'multiplied': 0.16; 'naming': 0.16; 'package).': 0.16; 'subject:access': 0.16; 'syntax.': 0.16; 'wrote:': 0.17; 'instance': 0.17; 'module,': 0.17; 'jan': 0.18; '(or': 0.18; 'module': 0.19; 'are:': 0.20; 'skip:" 30': 0.20; 'file.': 0.20; 'trying': 0.21; 'import': 0.21; 'meant': 0.21; 'not,': 0.21; 'supposed': 0.21; '"",': 0.22; 'object.': 0.22; 'of.': 0.22; 'skip:_ 20': 0.22; 'seems': 0.23; 'raise': 0.24; 'tried': 0.25; 'header:In-Reply-To:1': 0.25; 'skip:" 20': 0.26; '(most': 0.27; 'possibly': 0.27; 'rules': 0.27; 'see,': 0.27; 'message- id:@mail.gmail.com': 0.27; 'initial': 0.28; 'proposing': 0.29; 'skip:_ 10': 0.29; 'class': 0.29; "skip:' 10": 0.30; 'fri,': 0.30; 'gets': 0.32; 'file': 0.32; 'johnson': 0.32; 'could': 0.32; '11,': 0.33; 'crazy': 0.33; 'much.': 0.33; 'traceback': 0.33; 'problem': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'path': 0.35; 'skip:l 30': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'add': 0.36; 'explain': 0.36; 'but': 0.36; 'loaded': 0.36; 'modules': 0.36; "didn't": 0.36; 'should': 0.36; 'bad': 0.37; 'does': 0.37; 'being': 0.37; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'fact': 0.38; 'mean': 0.38; 'object': 0.38; 'some': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'called': 0.39; 'skip:" 10': 0.40; 'header:Received:5': 0.40; 'help': 0.40; 'think': 0.40; 'your': 0.60; 'you.': 0.61; 'times': 0.63; 'here': 0.65; 'treat': 0.65; 'direct': 0.69; 'intelligent': 0.71; 'special': 0.73; '2013': 0.84; 'clearer': 0.84; 'to:name:python': 0.84; 'rick': 0.91; 'beneficial': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; bh=r9KsYsEPbOGI6aKsGVu3p3GahmDUWPpk3cH11E+chZY=; b=m6eEjTEFAzS5VUt3KkJs5KjT46HqIrCp1flXmCuNyiXueqqDgvumtirf5rgxlzesHR uMsiuZUvFRueASSWTnoM9JPjbTuw8QQDzM3zL5DfyGE3utaL6RR2q/OFbkLgTgJuQGmK uwS2KlW/C/V9NK0CkVMH9qqh78JQaRp4dsbcDb5dk3ppUywPT7IwNcpWPMsO9FaNpQ7l TLzHLRoiJDsTfUrVun2dbVMMINAv2t4qe9I1nHlB0xl+VfpfqHHIZAnK5uSuaofLl0RW USwI5wl2kfrzV4b9MlVrxQQcz5r/Ziom8dhcNqcpMSLNcI5vwoTqtYJhnzDu5GPkEwwx wj3Q== MIME-Version: 1.0 In-Reply-To: <9b64719e-1e06-47fa-a7e6-692a3dd360d0@googlegroups.com> References: <8e9b2b0e-1c34-46cc-80c6-57fbb5fd756c@googlegroups.com> <50f03799$0$30003$c3e8da3$5496439d@news.astraweb.com> <9b64719e-1e06-47fa-a7e6-692a3dd360d0@googlegroups.com> From: Ian Kelly Date: Fri, 11 Jan 2013 23:55:40 -0700 Subject: Re: PyWart: Module access syntax To: Python Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 76 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1357973780 news.xs4all.nl 6853 [2001:888:2000:d::a6]:42172 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:36683 On Fri, Jan 11, 2013 at 9:34 PM, Rick Johnson wrote: > No the rules are: > * "Colon" must be used to access a "module" (or a package). > * "Dot" must be used to access a "module member". What about module a that does not natively contain module b, but imports it as a member like so? a.py: import b Must this be accessed as a:b or a.b? What about a module that is referenced by some other object that is not a module? Should it be "my_object.pickle_module" or "my_object:pickle_module"? > It's simple: MODULES&PACKAGES use colon, MODULE MEMBERS use dot. How many= times must i explain these simple rules? Since you didn't actually explain them at all in your initial post, I would have to say that once is enough. > If you don't know which names are modules and which names are members the= n how could a programmer possibly use the API in an intelligent way Steven? You might start by reading the documentation. > This syntax does not help the programmer much. Well, it can be beneficial= to the programmer if he gets a *PathError* because he foolishly tried to i= nstance a module named "simpledialog" when he actually meant to instance th= e object "simpledialog.SimpleDialog". (notice i did not use the word class!= ) The problem here is bad naming on the part of the library designer, not bad syntax. Why is SimpleDialog confusingly contained in a module also named simpledialog? This is not Java; there is no absurd requirement of one class per file. A clearer path to SimpleDialog would just be "lib.gui.tkinter.dialogs.SimpleDialog". > Traceback (most recent call last): > File "", line 1, in > dlg =3D lib:gui:tkinter:dialogs.simpledialog() > PathError: name 'simpledialog' is a module NOT a object! See, here is the thing that seems to be eluding you. In Python, modules *are* objects. You can bind names to them, just like any other object. You can add them to collections. You can introspect them. Hell, you can even subclass ModuleType and create modules that can be called or multiplied or iterated over or any crazy thing you can think of. Your : syntax is trying to treat modules as being somehow special, but the fact is that they're *not* special, which is why I think it's a bad idea. >> Does this mean there needs to four new be special methods: >> >> __getcolonattribute__ >> __getcolonattr__ >> __setcolonattr__ >> __delcolonattr__ > > Gawd no. getattr, setattr, and delattr will remain unchanged. The only ch= ange is how a /path/ to an identifier is "formed". Then how is ModuleType.__getattr__ supposed to know whether to raise a "PathError" or not, after it determines whether the requested object turned out to be a module or not? It has no way of knowing whether it was invoked by '.' or by ':' or by getattr or by direct invocation. Or are you instead proposing a new bytecode "LOAD_COLON_ATTR" to complement "LOAD_ATTR", and that every single occurrence of LOAD_ATTR in every program would then have to check whether the loaded object turned out to be a module and whether the object it was loaded from also happened to be a module, all just to raise an exception in that case instead of just giving the programmer what he wants?