diff options
author | Gunnar Aastrand Grimnes <gromgull@gmail.com> | 2013-05-02 14:40:55 +0200 |
---|---|---|
committer | Gunnar Aastrand Grimnes <gromgull@gmail.com> | 2013-05-02 14:40:55 +0200 |
commit | d9ae17b43419180eaf8c92c6f28ebd1d11d5aa1b (patch) | |
tree | 4555a671157fc3e46e0b2e28103193a99d6e3dc5 /examples | |
parent | bdbc2a580dd1c6064b665d6bbbc3bfff6f02c783 (diff) | |
download | rdflib-d9ae17b43419180eaf8c92c6f28ebd1d11d5aa1b.tar.gz |
moved paths from sparql package to top-level - make slicing return tuples, not always triples
Diffstat (limited to 'examples')
-rw-r--r-- | examples/resource.py | 10 | ||||
-rw-r--r-- | examples/slice.py | 4 |
2 files changed, 11 insertions, 3 deletions
diff --git a/examples/resource.py b/examples/resource.py index 51c0f46a..0f61c92a 100644 --- a/examples/resource.py +++ b/examples/resource.py @@ -30,8 +30,16 @@ print "Bill's friend: ", bill.value(FOAF.knows).value(FOAF.name) # slicing ([] syntax) can also be used: -print list(bill[FOAF.knows]) # return triples! +print "Bill knows: ", +for friend in bill[FOAF.knows]: + print friend[FOAF.name].next(), " " +# or even quicker with paths: +print "Bill knows: ", +for friend in bill[FOAF.knows/FOAF.name]: + print friend + +# setting single properties is also possible: bill[RDFS.label]=Literal("William") print g.serialize(format='n3') diff --git a/examples/slice.py b/examples/slice.py index a06b3ee8..390ba481 100644 --- a/examples/slice.py +++ b/examples/slice.py @@ -16,11 +16,11 @@ graph = Graph() graph.load("foaf.rdf") -for person,_,_ in graph[: RDF.type : FOAF.Person]: +for person in graph[: RDF.type : FOAF.Person]: friends = list(graph[person:FOAF.knows * '+'/FOAF.name]) if friends: print "%s's circle of friends:"%graph.value(person, FOAF.name) - for _,_,name in friends: + for name in friends: print name |