Python API: Option Export Topic is solved

Questions on using the GAMS APIs (Python, .NET, etc.)
Post Reply
Jan
User
User
Posts: 7
Joined: 4 years ago

Python API: Option Export

Post by Jan » 1 year ago

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

User avatar
bussieck
Moderator
Moderator
Posts: 615
Joined: 4 years ago

Re: Python API: Option Export

Post by bussieck » 1 year ago

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

Post Reply