I have a program that I would like to automate, removing the pre-processing steps as much ass possible. Reading through a dataset, the program generates series of function calls that get used in a subsequent step. Currently I just copy the generated calls stored in the variable into the file, but I would like to skip this step if possible
##preprocessing steps here...
bindings = ["g.bind('rdf', URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#'))",
"g.bind('bf', URIRef('http://id.loc.gov/ontologies/bibframe/'))",
"g.bind('bflc', URIRef('http://id.loc.gov/ontologies/bflc/'))"]
### then the bind calls are added to the function below.
g = rdflib.Graph()
g.bind('rdf', URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#'))
g.bind('bf', URIRef('http://id.loc.gov/ontologies/bibframe/'))
g.bind('bflc', URIRef('http://id.loc.gov/ontologies/bflc/'))```
g.parse(data= graph, format='nt')
g.serialize(format='turtle')
How can I remove the copying and pasting from the process?
"g.bind('rdf', URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#'))"as if they contained valid Python code, right? This is exactly what you can do withevalandexecfunctions.evalorexecwhere they're not absolutely necessary. If you want to defer a function call until later, you can wrap it in a lambda, likelambda: g.bind(...). However, there is probably no need for that here either.