Ask Your Question
1

Extract contingencies for dfax file?

asked 2012-08-14 09:39:21 -0500

waltterval gravatar image

updated 2012-08-16 10:08:21 -0500

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
edit retag flag offensive close merge delete

Comments

I couldn't find one either. Can you read the contingencies from the `.con` file instead?

JervisW gravatar imageJervisW ( 2012-08-14 09:58:09 -0500 )edit

@JervisW Actually what I need is a eassy way to extract the name of my contingencies that are in .con file? Any idea?

waltterval gravatar imagewaltterval ( 2012-08-14 10:23:55 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2012-08-15 06:59:08 -0500

JervisW gravatar image

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?

edit flag offensive delete link more

Comments

@JervisW I will check it and i'll let you know if work as I need. Thanks

waltterval gravatar imagewaltterval ( 2012-08-15 17:31:32 -0500 )edit

@JervisW I did a little change to your script, I updated my question to post the final code. Thank you

waltterval gravatar imagewaltterval ( 2012-08-16 10:03:19 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

[hide preview]

Question Tools

1 follower

Stats

Asked: 2012-08-14 09:39:21 -0500

Seen: 617 times

Last updated: Aug 16 '12