Using operators that require multiple input files in python
Added by Alexander Koutsouris over 10 years ago
Hi,
I am trying to learn how to use CDO in combination with Python -I have som experience with CDO but I'm new to python.
I want to use the CDO commando: cdo mergetime ifile1 ifile2 ofile
In python, I have written it as: cdo.mergetime(input=ifile1, ifile2, output=ofile)
This renders the error "non-keyword arg after keyword arg". I have tried to write the code in a range of different ways based on python tutorials and the CDO wiki but I haven't managed to get it to work.
I would be very glad to get some help with this.
Thanks
-Alex
Replies (4)
RE: Using operators that require multiple input files in python - Added by Ralf Mueller over 10 years ago
Alexander Koutsouris wrote:
Hi,
I am trying to learn how to use CDO in combination with Python -I have som experience with CDO but I'm new to python.
I want to use the CDO commando: cdo mergetime ifile1 ifile2 ofile
In python, I have written it as: cdo.mergetime(input=ifile1, ifile2, output=ofile)
cdo.mergetime(input=" ".join((ifile1,ifile2)), output=ofile)
should work.
hth
ralf
RE: Using operators that require multiple input files in python - Added by Ashwin D almost 2 years ago
Old thread I know but I have a situation in which ifile1 and ifile2 are not hard coded. The number of files is also not the same each time join is called. In other words it is dynamic input.
If I figure out a solution I will for sure share it here.
RE: Using operators that require multiple input files in python - Added by Ashwin D almost 2 years ago
`cdo.merge(input=" ".join(([fileTmpDictionary[key] for key in sorted(fileTmpDictionary,reverse=True)])), output='tmpFile.nc')`
RE: Using operators that require multiple input files in python - Added by Ralf Mueller almost 2 years ago
looks good as a solution. But you can specify a list as input value. cdo.py will do the join() inside for you
cheers
ralf