Page 1 of 1

Python API: Option Export

Posted: Thu May 14, 2020 8:08 am
by Jan
Hi

I am trying to export options to a file with GAMS API under PYthon 3.8 using the follwing code:

Code: Select all

import gams
import os
ws = gams.GamsWorkspace(os.getcwd())
opt = ws.add_options()
opt.defines["test"] = 5
opt.export("./test.gms")
This raises an error in options.py:
~\anaconda3\envs\py38_gams\lib\site-packages\gams\options.py in export(self, file_path)
2212 file.write(cfgModelTypeName(self._cfg, i) + "=" + self._selected_solvers + "\n")
2213 if len(self.defines) > 0:
-> 2214 for k,v in self.defines:
2215 file.write("--" + k + "=" + v + "\n")
2216 file.close()

ValueError: too many values to unpack (expected 2)


options.defines seems to be implemented as dictionary, and I wonder whether the "for" statement misses a ".items()" statement. Or do I miss something here?

Best regards
Jan

Re: Python API: Option Export

Posted: Fri May 15, 2020 8:02 am
by bussieck
Jan,

This is indeed a bug. We'll fix this. Good that GAMS distributes the Python API now in source, so you can fix yourself and don't have to wait for GAMS to patch and do another release. BTW, there is the expectation that the values of the defines dictionary are strings. One could use str() internally to always try to convert them to strings...

-Michael