Newbie help - Programming the Semantic Web with Python

Bruce Whealton bruce at whealton.info
Sun Jul 17 03:35:22 CEST 2011


Hello,
           So, regarding the path that python uses to find modules, I read 
the link that you sent.  Suppose, I open IDLE and start an interactive 
session.  That would mean the input script location is wherever python is 
installed, correct?  I did add an environment variable PYTHONPATH which did 
not even exist when I first installed Python.  I figured I would want to 
have a directory where I could store modules that might interest me.  I 
might want to expand that into a package style path later.
         Now, if I was going to create an application to run on the web, I 
guess those included modules would have to get compiled with the rest of the 
code for it to work, right?
Bruce

-----Original Message----- 
From: Chris Angelico
Sent: Saturday, July 09, 2011 10:10 PM
To: python-list at python.org
Subject: Re: Newbie help - Programming the Semantic Web with Python

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
-- 
http://mail.python.org/mailman/listinfo/python-list 




More information about the Python-list mailing list