First time here? We are a friendly community of Power Systems Engineers. Check out the FAQ!
1 | initial version |
Hi all? I want to know if exists a way to extract the name of the contingencies from a dfax files. I have a dfax file, and I'm lookig for an API that give the contingencies in a variable. Is this possible?
2 | No.2 Revision |
Hi all? I want to know if exists a way to extract the name of the contingencies from a dfax files. I have a dfax file, and I'm lookig for an API that give the contingencies in a variable. Is this possible?
Well I took the code that Jervis wrote and did a little change.
With Jervis'code I got this answer ["'S1'\n", "'S2'\n", "'S3'\n", "'S4'\n", "'S5'\n", "'S6'\n", "'S7'\n", "'S8'\n", "'S9'\n", "'S10'\n", "'S11'\n", "'S12'\n", "'S13'\n", "'S14'\n", "'S15'\n", "'S16'\n", "'S17'\n", "'S18'\n", "'S19'\n", "'S20'\n", "'S21'\n", "'S22'\n", "'S23'\n", "'S24'\n", "'S25'\n", "'S26'\n", "'S27'\n", "'S28'\n", "'S30'\n", "'S31'\n", "'S32'\n"]
With the changed code I got what I really need: ['S1', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7', 'S8', 'S9', 'S10', 'S11', 'S12', 'S13', 'S14', 'S15', 'S16', 'S17', 'S18', 'S19', 'S20', 'S21', 'S22', 'S23', 'S24', 'S25', 'S26', 'S27', 'S28', 'S30', 'S31', 'S32']
Here is the code:
contingency_names = []
with open('Contingencias_SER_EMT2012_SAL2.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)
contingency_ID = []
for contingency_name in contingency_names:
contingency_ID.append(contingency_name[1:-2])
print "\n contingency_ID = ", contingency_ID