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
|
||||
- Added README
|
||||
- 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)
|
||||
expr= ("%s%s%s") % (expr[0:start-2],res,expr[end+1:])
|
||||
elif symbol=="ρ": #Rename
|
||||
params=parameters.replace(",","\",\"").replace("➡","\",\"").replace(" ","")
|
||||
res="%s.rename(\"%s\")" % (internal,params)
|
||||
params=parameters.replace(",","\",\"").replace("➡","\":\"").replace(" ","")
|
||||
res="%s.rename({\"%s\"})" % (internal,params)
|
||||
expr= ("%s%s%s") % (expr[0:start-2],res,expr[end+1:])
|
||||
else:
|
||||
res="(%s)" % (internal)
|
||||
|
14
relation.py
14
relation.py
@ -145,19 +145,19 @@ class relation (object):
|
||||
|
||||
|
||||
|
||||
def rename(self,*params):
|
||||
'''Operation rename. Takes an even number of parameters: (old,new,old,new....)
|
||||
Will replace the 1st parameter with the 2nd, the 3rd with 4th, and so on...
|
||||
def rename(self,params):
|
||||
'''Operation rename. Takes a dictionatu
|
||||
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'''
|
||||
result=[]
|
||||
|
||||
newt=relation()
|
||||
newt.header=header(list(self.header.attributes))
|
||||
|
||||
for i in range(len(params)):
|
||||
if i%2==0:
|
||||
if (newt.header.rename(params[i],params[i+1])) == False:
|
||||
return None
|
||||
for i in params:
|
||||
if (newt.header.rename(i,params[i])) == False:
|
||||
return None
|
||||
|
||||
newt.content=list(self.content)
|
||||
return newt
|
||||
|
Loading…
x
Reference in New Issue
Block a user