Bruno
Bruno

Reputation: 97

How to pprint to file parameters of an Instance from an AbstractModel in Pyomo?

I´m trying to inspect an Instance of an AbstractModel on Pyomo for checking if parameters reading was OK.

For doing so, I´d like to print the parameters values considered in the instance into a txt file.

for doing so, I´ve tried:

for element in instance.component_objects(Param,descend_into=True):
   element.pprint(filename=some_filename)

But what I get is that filename is not a valid argument for pprint. Any hints on what could I do?

Upvotes: 0

Views: 546

Answers (1)

Qi Chen
Qi Chen

Reputation: 1718

pprint expects an output stream to write to. Try:

with open('file.txt', 'w') as output_file:
    element.pprint(output_file)

Upvotes: 2

Related Questions