Changed internal rename method. Now uses a dictionary
git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@50 014f5005-505e-4b48-8d0a-63407b615a7c
This commit is contained in:
parent
772eb4f156
commit
278036081f
@ -38,4 +38,5 @@
|
|||||||
0.7
|
0.7
|
||||||
- Added README
|
- Added README
|
||||||
- Expressions between quotes aren't parsed anymore
|
- Expressions between quotes aren't parsed anymore
|
||||||
- When adding a relation, the file must be choosen 1st, and then the default relation's name is the same as the filename
|
- When adding a relation, the file must be choosen 1st, and then the default relation's name is the same as the filename
|
||||||
|
- Changed internal rename method. Now uses a dictionary
|
@ -106,8 +106,8 @@ def parse(expr):
|
|||||||
res="%s.selection(\"%s\")" % (internal,parameters)
|
res="%s.selection(\"%s\")" % (internal,parameters)
|
||||||
expr= ("%s%s%s") % (expr[0:start-2],res,expr[end+1:])
|
expr= ("%s%s%s") % (expr[0:start-2],res,expr[end+1:])
|
||||||
elif symbol=="ρ": #Rename
|
elif symbol=="ρ": #Rename
|
||||||
params=parameters.replace(",","\",\"").replace("➡","\",\"").replace(" ","")
|
params=parameters.replace(",","\",\"").replace("➡","\":\"").replace(" ","")
|
||||||
res="%s.rename(\"%s\")" % (internal,params)
|
res="%s.rename({\"%s\"})" % (internal,params)
|
||||||
expr= ("%s%s%s") % (expr[0:start-2],res,expr[end+1:])
|
expr= ("%s%s%s") % (expr[0:start-2],res,expr[end+1:])
|
||||||
else:
|
else:
|
||||||
res="(%s)" % (internal)
|
res="(%s)" % (internal)
|
||||||
|
14
relation.py
14
relation.py
@ -145,19 +145,19 @@ class relation (object):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
def rename(self,*params):
|
def rename(self,params):
|
||||||
'''Operation rename. Takes an even number of parameters: (old,new,old,new....)
|
'''Operation rename. Takes a dictionatu
|
||||||
Will replace the 1st parameter with the 2nd, the 3rd with 4th, and so on...
|
Will replace the itmem with its content.
|
||||||
|
For example if you want to rename a to b, provide {"a":"b"}
|
||||||
If an "old" field doesn't exist, None will be returned'''
|
If an "old" field doesn't exist, None will be returned'''
|
||||||
result=[]
|
result=[]
|
||||||
|
|
||||||
newt=relation()
|
newt=relation()
|
||||||
newt.header=header(list(self.header.attributes))
|
newt.header=header(list(self.header.attributes))
|
||||||
|
|
||||||
for i in range(len(params)):
|
for i in params:
|
||||||
if i%2==0:
|
if (newt.header.rename(i,params[i])) == False:
|
||||||
if (newt.header.rename(params[i],params[i+1])) == False:
|
return None
|
||||||
return None
|
|
||||||
|
|
||||||
newt.content=list(self.content)
|
newt.content=list(self.content)
|
||||||
return newt
|
return newt
|
||||||
|
Loading…
x
Reference in New Issue
Block a user