Created a loop including CSVs Topic is solved

questions about GAMS' tools
Post Reply
richard
User
User
Posts: 27
Joined: 5 years ago

Created a loop including CSVs

Post by richard »

Hi all,

Is there any way to refer to the CSV files in a loop?
All my files have systematic names: file1.csv, file2.csv etc. How do I create a loop including all the files?

I am looking for something like this:

set j /1*10/
loop(j,
$include "filej.csv")
How do I go about it?
User avatar
Renger
Posts: 639
Joined: 7 years ago

Re: Created a loop including CSVs

Post by Renger »

Hi Richard

Just starting to learn how to use embededded code in Gams. Here a solution with python:

Code: Select all

$onEmbeddedCode Python:
  f = open('myinclude.inc', 'w')
  for i in range(10):
     f.write('$include'+'" file' + str(i)+'.csv"\n')
  f.close()
$offEmbeddedCode

$include myinclude.inc
Hope this helps
Cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
richard
User
User
Posts: 27
Joined: 5 years ago

Re: Created a loop including CSVs

Post by richard »

Hi @Renger , Thanks a lot ! It was very helpful.
Post Reply