Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Here is a simple script to get the contingencies names from a .con file:

contingency_names = []
with open('contingency.con') as confile:

 for line in confile:

   if line.strip().lower().startswith('contingency'):

     # assumes the last word on the line is the contingency name.
     words = line.split(' ')
     name = words[-1]

     contingency_names.append(name)

print contingency_names

I've assumed that your file looks a bit like this:

CONTINGENCY firstcontingency
REMOVE UNIT 3 FROM BUS 20002
END
CONTINGENCY somethingelse
...

The script wont work if:

  1. You have spaces in your contingency names
  2. There is text on the CONTINGENCY line other than the word CONTINGENCY and the contingency name

Does it work for you?