Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #75310

Re: Prob. Code Downloaded for Programming the Semantic Web (python code)

Newsgroups comp.lang.python
Date 2014-07-28 03:39 -0700
References <8e593a0d-cf61-4b1a-8273-8309496e3696@googlegroups.com> <mailman.12329.1406344508.18130.python-list@python.org>
Message-ID <52662cf8-67bd-4005-adb3-05179b30cf11@googlegroups.com> (permalink)
Subject Re: Prob. Code Downloaded for Programming the Semantic Web (python code)
From Bruce Whealton <futurewavewebdevelopment@gmail.com>

Show all headers | View raw


On Friday, July 25, 2014 9:28:32 PM UTC-4, Steven D'Aprano wrote:
> On Fri, 25 Jul 2014 17:06:17 -0700, Bruce Whealton wrote:
Steven,
See below please.  The explanation did help.   
> 
> > 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
> 
I setup Eclipse to use python 2.7.x and tried to run this and it just gave an error on line 9 where the def add function is declared.  It just says invalid syntax and points at the parentheses that are in the function definition
def add(self, (subj, pred, obj)):
So, from what you said, and others, it seems like this should have worked but eclipse would not run it.  I could try to load it into IDLE.
> 
> 
> 
> In Python 3, that functionality was dropped and is no longer allowed. Now
> you have to use the longer form.
>
I'm not sure I follow what the longer method is.  Can you explain that more, please. 
> 
> 
> [...]
> 
> > 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:
> 
The full code listing should be available in the code paste link that I included.
> 
> 
>     list(self.triples((sub, pred, obj)))
> 
> 
> 
> that list then being bound to the name "triples".
> 
> 
Thanks, the explanation helped,
Bruce

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Prob. Code Downloaded for Programming the Semantic Web (python code) Bruce Whealton <futurewavewebdevelopment@gmail.com> - 2014-07-25 17:06 -0700
  Re: Prob. Code Downloaded for Programming the Semantic Web (python code) Skip Montanaro <skip@pobox.com> - 2014-07-25 19:21 -0500
  Re: Prob. Code Downloaded for Programming the Semantic Web (python code) Dan Stromberg <drsalists@gmail.com> - 2014-07-25 17:52 -0700
  Re: Prob. Code Downloaded for Programming the Semantic Web (python code) Ian Kelly <ian.g.kelly@gmail.com> - 2014-07-25 19:39 -0600
  Re: Prob. Code Downloaded for Programming the Semantic Web (python code) Steven D'Aprano <steve+gmane@pearwood.info> - 2014-07-26 11:28 +1000
    Re: Prob. Code Downloaded for Programming the Semantic Web (python code) Bruce Whealton <futurewavewebdevelopment@gmail.com> - 2014-07-28 03:39 -0700
      Re: Prob. Code Downloaded for Programming the Semantic Web (python code) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-07-28 15:28 +0000
        Re: Prob. Code Downloaded for Programming the Semantic Web (python code) Bruce Whealton <futurewavewebdevelopment@gmail.com> - 2014-07-28 17:57 -0700
  Re: Prob. Code Downloaded for Programming the Semantic Web (python code) Chris Angelico <rosuav@gmail.com> - 2014-07-26 13:25 +1000
    Re: Prob. Code Downloaded for Programming the Semantic Web (python code) Bruce Whealton <futurewavewebdevelopment@gmail.com> - 2014-07-28 04:07 -0700
  Re: Prob. Code Downloaded for Programming the Semantic Web (python code) Terry Reedy <tjreedy@udel.edu> - 2014-07-26 03:05 -0400

csiph-web