Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!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; 'parameters': 0.04; 'syntax': 0.04; 'argument': 0.05; 'python)': 0.05; '"""': 0.07; 'allowed.': 0.07; 'subject:code': 0.07; 'variables': 0.07; 'string': 0.09; 'converts': 0.09; 'function:': 0.09; 'method:': 0.09; 'obj': 0.09; 'parameter': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'snippet': 0.09; 'python': 0.11; 'def': 0.12; '(remember': 0.16; 'add(self,': 0.16; 'declarations': 0.16; 'eclipse': 0.16; 'expects': 0.16; 'parentheses': 0.16; 'received:80.91.229.3': 0.16; 'received:internode.on.net': 0.16; 'received:on.net': 0.16; 'received:plane.gmane.org': 0.16; 'remove(self,': 0.16; 'subject:Programming': 0.16; 'tuple': 0.16; 'variables:': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; '(not': 0.18; 'split': 0.19; 'written': 0.21; 'seems': 0.21; 'example': 0.22; 'bruce': 0.22; 'header:User-Agent:1': 0.23; 'expanded': 0.24; 'passes': 0.24; 'subject:Code': 0.24; '(or': 0.24; 'header:X-Complaints-To:1': 0.27; 'tried': 0.27; 'function': 0.29; "doesn't": 0.30; 'list:': 0.30; 'sets': 0.30; '-0700,': 0.31; 'dropped': 0.31; 'steven': 0.31; 'fri,': 0.33; 'subject:the': 0.34; 'could': 0.34; 'subject: (': 0.35; 'form.': 0.35; 'but': 0.35; 'there': 0.35; 'method': 0.36; 'charset:us- ascii': 0.36; 'should': 0.36; 'too': 0.37; 'two': 0.37; 'list': 0.37; 'being': 0.38; 'version,': 0.38; 'needed': 0.38; 'whatever': 0.38; 'to:addr:python-list': 0.38; 'short': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'even': 0.60; 'remove': 0.60; 'removing': 0.60; 'then,': 0.60; 'length': 0.61; 'first': 0.61; 'here:': 0.62; 'back': 0.62; 'name': 0.63; 'places': 0.64; 'more': 0.64; 'effectively': 0.66; 'subject:. ': 0.67; 'header:Reply-To:1': 0.67; 'line,': 0.68; 'reply-to:no real name:2**0': 0.71; 'cut': 0.74; 'jul': 0.74; 'confusing': 0.84; 'presumably': 0.84; 'received:118': 0.84; 'items,': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Steven D'Aprano Subject: Re: Prob. Code Downloaded for Programming the Semantic Web (python code) Date: Sat, 26 Jul 2014 11:28:32 +1000 References: <8e593a0d-cf61-4b1a-8273-8309496e3696@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: ppp118-209-248-249.lns20.mel6.internode.on.net User-Agent: KNode/0.10.4 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: steve+gmane@pearwood.info 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: 67 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1406344508 news.xs4all.nl 2935 [2001:888:2000:d::a6]:47431 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:75225 On Fri, 25 Jul 2014 17:06:17 -0700, Bruce Whealton wrote: > OK, Eclipse with PyDev doesn't like this first line, with the function: > def add(self, (sub, pred, obj)): In Python 2, you could include parenthesised parameters inside function declarations as above. That is effectively a short cut for this version, where you collect a single argument and then expand it into three variables: def add(self, sub_pred_obj): sub, pred, obj = sub_pred_obj In Python 3, that functionality was dropped and is no longer allowed. Now you have to use the longer form. [...] > There are other places where I thought that there were too many > parentheses and I tried removing one set of them. For example this > snippet here: > > def remove(self, (sub, pred, obj)): > """ > Remove a triple pattern from the graph. """ > triples = list(self.triples((sub, pred, obj))) Firstly, the remove method expects to take a *single* argument (remember that self is automatically provided by Python) which is then automatically expanded into three variables sub, pred, obj. So you have to call it with a list or tuple of three items (or even a string of length exactly 3). Then, having split this list or tuple into three items, it then joins them back again into a tuple: (sub, pred, obj) passes that tuple to the triples method: self.triples((sub, pred, obj)) (not shown, but presumably it uses the same parenthesised parameter trick), and then converts whatever triples returns into a list: list(self.triples((sub, pred, obj))) that list then being bound to the name "triples". > Are the two sets parentheses needed after self.triples? That syntax is > confusing to me. It seems that it should be triples = > list(self.triples(sub, pred, obj)) It's needed because the triples method is written def triples(self, (sub, pred, obj)): instead of the more obvious: def triples(self, sub, pred, obj): -- Steven