Newbie help - Programming the Semantic Web with Python
Chris Angelico
rosuav at gmail.com
Sat Jul 9 22:10:31 EDT 2011
On Sun, Jul 10, 2011 at 11:32 AM, Bruce Whealton <bruce at whealton.info> wrote:
problem with is this line:
> def add(self, (sub, pred, obj)):
> I think the problem is with the parentheses before the sub. I removed those and that seemed to fix that error or make it go away. I don’t remember how I figured that out, It should be on the Errata page for sure.
> Then it has a problem with this line:
> print list(g.triples((None, None, None)))
> If I was using python 3, it would require () around the thing that is going to be printed, right? Maybe python 2.7 doesn’t like this line for the same reason.
>
The issue there is with tuple unpacking. To match the older syntax,
don't touch the call, but change the definition thus:
def add(self, args):
(sub, pred, obj)=args
Or, of course, simply list the arguments directly, rather than in a
tuple; but that requires changing every call (if it's a small program
that may not be a problem).
You're right about needing parentheses around the print() call; in
Python 2 it's a statement, but in Python 3, print is a function like
any other.
Regarding the module search path, this may help:
http://docs.python.org/dev/tutorial/modules.html#the-module-search-path
Chris Angelico
More information about the Python-list
mailing list