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

Bruce Whealton futurewavewebdevelopment at gmail.com
Tue Jul 29 02:57:19 CEST 2014


On Monday, July 28, 2014 11:28:40 AM UTC-4, Steven D'Aprano wrote:
> On Mon, 28 Jul 2014 03:39:48 -0700, Bruce Whealton wrote:
Stephen,
    I went to my Ubuntu box inside vmware and added a #!/usr/bin/env python2.7 to the top.  Then I made the file executable and it ran the code perfectly. 

> 
> First step is to confirm that Eclipse actually is using Python 2.7. Can 
> 
> you get it to run this code instead? Put this in a module, and then run 
> 
> it:
> 
> 
> 
> import sys
> 
> print(sys.version)
> 
> 
I had both python2.7 and python3.4.  I could be less specific with my shebang line but what the heck.  
> 
> 
> 
I then installed pydev into my eclipse environment within the Ubuntu virtual machine and it ran the program just fine.  So, I suspect the extra character was 
only an issue on Windows.  I thought I had it setup to show even hidden characters.  
Anyway, thanks so much for all the help...everyone.  It might be interesting for me to convert this to a module that runs with python 3.
Bruce 
> 
> 
> > 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.
> 
> 
> 
> Whenever you have trouble with one IDE, it's good to get a second opinion 
> 
> in another IDE. They might both be buggy, but they're unlikely to both 
> 
> have the same bug.
> 
> 
> 
> Also, try to run the file directly from the shell, without an IDE. from 
> 
> the system shell (cmd.exe if using Windows, bash or equivalent for 
> 
> Linux), run:
> 
> 
> 
> python27 /path/to/yourfile.py
> 
> 
> 
> You'll obviously need to adjust the pathname, possibly even give the full 
> 
> path to the Python executable.
> 
> 
> 
> 
> 
> [...]
> 
> >> 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.
> 
> 
> 
> I referred to the parenthesised parameter version as a short cut for a 
> 
> method that takes a single argument, then manually expands that argument 
> 
> into three items. Let me show them together to make it more obvious:
> 
> 
> 
> # Unparenthesised version, with manual step.
> 
> def add(self, sub_pred_obj):
> 
>     sub, pred, obj = sub_pred_obj
> 
>     do_stuff_with(sub or pred or obj)
> 
> 
> 
> # Parenthesised shortcut.
> 
> def add(self, (sub, pred, obj)):
> 
>     do_stuff_with(sub or pred or obj)
> 
> 
> 
> Both methods take a single argument, which must be a sequence of exactly 
> 
> three values. The second version saves a single line, hence the first 
> 
> version is longer :-)
> 
> 
> 
> 
> 
> -- 
> 
> Steven




More information about the Python-list mailing list