Closed brettdewoody closed 5 years ago
Optimize function is a generator, and you iterate over it in for loop after that it will be completed and empty for next iterations in export function. If you want both print lineup and export you should convert generator into list:lineups = list(optimizer.optimize(n=20))
, in this case you will wait all lineups creation. If you want to print lineup on each step and don't want to wait all completion collect them to additional list:
lineups = []
# Display the lineups
for lineup in optimizer.optimize(n=20):
lineups.append(lineup)
print(lineup.players)
# Export the lineups
exporter = CSVLineupExporter(lineups)
exporter.export(file)
Great, thank you. I'm currently learning Python so hopefully I don't need to ask about these things going forward.
I'd like to combine
print()
withCSVLineupExporter
to view the generated lineups in the Python interpreter, and export the lineups to a.csv
file.When I combine both
print()
andinto the same script, the exported file is always empty.
Here's a basic example: