I had asked this question and thought that I had it solved but I could not get the text defined as variables. Below is the text file. I would like to specify a line and the length and set that to a variable. In the Example below the items in Red, I would like them to be an Interger. The first one -571.5 possibly set to ATC1, EX. INT(ATC1) = line(21) [0:9]. The one that is Black and bold would be a string STR(LE1) = line(21) [29:79]. The one in red is also a string line (22) [90:137]. I tried to get the code as close as I know. The location of these numbers should not change but their values will change. The Items should not go past their corresponding Labels. Ex. LE1 could be as long as <-----Limiting constraint------> in the same location just down 1 line.

All the items that are Bold Red would be integers, the ones in Bold Black and Bold Green would be strings. I am hoping to take these Items out and set them = to a variable.

I hope this is clear. Thanks for the help.
Joe

PSS(R)MUST 9.2 -- Managing and Utilizing System Transmission -- MON, SEP 28 2009 15:12
2008 FRCC LFDB - 90% LOAD
2009 SUMMER BASE
Case.File C:\HourlyATC\ATC090928\OPCASE21.sav
Subsys.File C:\HourlyATC\subsystem.sub
Monit.File C:\HourlyATC\monitor.mon
Contin.File C:\HourlyATC\contingency.con
Exclud.File C:\HourlyATC\exclude.exc

Study transfer level - 1000.0 MW. Total violations: 7
First violation - -571.5 MW.

Study transfer. From FMPP_EXA To FPL_IMA . Transfer level - 1000.0 MW


Violations report ordered by transfer capability. Total 7 violations


FCITC TDF LODF <--------- Limiting constraint ---------> <--------- Contingency description ---------> Ncon PreShift Rating PTDF IntBase FnlBase
-571.5 -0.03039 -0.19893 6106 I-STATE 230 6104 TENOROC 230 1 C:9100-9120D 446 -454.4 -437.0 -0.01716 -377.1 -367.3
Open 9100 RECKER 230 9120 SELOSE 230 1
Study transfer level - 1000.0 MW. Total violations: 17
First violation - -626.4 MW.

Study transfer. From FMPP_EXA To PEF_IMA . Transfer level - 1000.0 MW


Violations report ordered by transfer capability. Total 17 violations


FCITC TDF LODF <--------- Limiting constraint ---------> <--------- Contingency description ---------> Ncon PreShift Rating PTDF IntBase FnlBase
-626.4 -0.04873 0.30911 6106 I-STATE 230 6104 TENOROC 230 1 C: 7890 OSCEOLA 230 9190 AGNES-RX 230 1 414 -467.5 -437.0 -0.04950 -377.1 -346.1
Open 7890 OSCEOLA 230 9190 AGNES-RX 230 1
Study transfer level - 1000.0 MW. Total violations: 5
First violation - -443.2 MW.

Study transfer. From FMPP_EXA To TECO_IMA . Transfer level - 1000.0 MW


Violations report ordered by transfer capability. Total 5 violations


FCITC TDF LODF <--------- Limiting constraint ---------> <--------- Contingency description ---------> Ncon PreShift Rating PTDF IntBase FnlBase
-443.2 -0.03919 -0.19893 6106 I-STATE 230 6104 TENOROC 230 1 C:9100-9120D 446 -454.4 -437.0 -0.02746 -377.1 -365.0
Open 9100 RECKER 230 9120 SELOSE 230 1
Study transfer level - 1000.0 MW. Total violations: 6
First violation - 1145.8 MW.

Study transfer. From FPL_EXA To FMPP_IMA . Transfer level - 1000.0 MW


Violations report ordered by transfer capability. Total 6 violations


FCITC TDF LODF <--------- Limiting constraint ---------> <--------- Contingency description ---------> Ncon PreShift Rating PTDF IntBase FnlBase
1145.8 -0.11840 0.52227 8860 SO GIB-S 230 8900 B BEND 230 1 C:8500-8900 592 -613.3 -749.0 -0.09149 -368.8 -473.6
Open 8500 11TH AVE 230 8900 B BEND 230 1
Study transfer level - 1000.0 MW. Total violations: 6
First violation - 1481.3 MW.

Study transfer. From PEF_EXA To FMPP_IMA . Transfer level - 1000.0 MW


Violations report ordered by transfer capability. Total 6 violations


FCITC TDF LODF <--------- Limiting constraint ---------> <--------- Contingency description ---------> Ncon PreShift Rating PTDF IntBase FnlBase
1481.3 0.09024 0.51643 2167 WINDERME 230 5701 SO WOOD 230 1 C:5353-5800 581 233.3 367.0 0.08419 150.0 274.7
Open 5352 CAN ISL 230 5800 OUCCITP1 230 1
Study transfer level - 1000.0 MW. Total violations: 5
First violation - 1525.8 MW.

Study transfer. From TECO_EXA To FMPP_IMA . Transfer level - 1000.0 MW


Violations report ordered by transfer capability. Total 5 violations


FCITC TDF LODF <--------- Limiting constraint ---------> <--------- Contingency description ---------> Ncon PreShift Rating PTDF IntBase FnlBase
1525.8 -0.14795 0.44375 8000 SHELD 230 8370 JUNEAU 230 1 C:8700-8400 600 -571.3 -797.0 -0.12009 -405.1 -588.3
Open 8400 CHAPMAN 230 8700 GANNON 230 1
Study transfer level - 1000.0 MW. Total violations: 6
First violation - 1268.3 MW.

Study transfer. From IPP_REL_EXA To FMPP_IMA . Transfer level - 1000.0 MW


Violations report ordered by transfer capability. Total 6 violations


FCITC TDF LODF <--------- Limiting constraint ---------> <--------- Contingency description ---------> Ncon PreShift Rating PTDF IntBase FnlBase
1268.3 -0.38320 0.92478 461 CAPE K 230 5703 IND RIV 230 2 C: 461 CAPE K 230 5703 IND RIV 230 1 360 -311.0 -797.0 -0.19986 -162.2 -415.7
Open 461 CAPE K 230 5703 IND RIV 230 1
Study transfer level - 1000.0 MW. Total violations: 6
First violation - 681.1 MW.

Study transfer. From IPP_REL_EXA To FPL_IMA . Transfer level - 1000.0 MW


Violations report ordered by transfer capability. Total 6 violations


FCITC TDF LODF <--------- Limiting constraint ---------> <--------- Contingency description ---------> Ncon PreShift Rating PTDF IntBase FnlBase
681.1 0.16806 -0.23199 464 MALABAR 230 708 WYOMING 230 1 C: 275 MARTIN 500 476 POINSETT 500 1 149 516.7 631.2 0.09595 261.1 326.4
Open 275 MARTIN 500 476 POINSETT 500 1
Study transfer level - 1000.0 MW. Total violations: 5
First violation - -787.9 MW.

Study transfer. From IPP_REL_EXA To PEF_IMA . Transfer level - 1000.0 MW


Violations report ordered by transfer capability. Total 5 violations


FCITC TDF LODF <--------- Limiting constraint ---------> <--------- Contingency description ---------> Ncon PreShift Rating PTDF IntBase FnlBase
-787.9 -0.03316 - 6106 I-STATE 230 6104 TENOROC 230 1 Base Case -377.1 -351.0

Study transfer level - 1000.0 MW. Total violations: 3
First violation - 569.5 MW.

Study transfer. From IPP_REL_EXA To TECO_IMA . Transfer level - 1000.0 MW


Violations report ordered by transfer capability. Total 3 violations


FCITC TDF LODF <--------- Limiting constraint ---------> <--------- Contingency description ---------> Ncon PreShift Rating PTDF IntBase FnlBase
569.5 -0.03573 -0.31618 6106 I-STATE 230 6104 TENOROC 230 1 C: 6105 CREWSLK 230 9050 PEBB 230 1 412 -416.7 -437.0 -0.01112 -377.1 -383.5
Open 6105 CREWSLK 230 9050 PEBB 230 1

If this is truly your text file, I feel sorry for you!

I can't copy the text to test...
Is this to be a html file ? Are the <br /> tags or are they supposed to show CR.
Your BBCodes don't work...
How can you select one line if all your file seems to be on an unique line ?

Hi, Jice and Bumsfeld,

I noticed that the bb codes did not seem to work. I am rather new to this but I have posted before and they worked. I thought maybe the bbcodes would work once I hit submit. This is just a text file. I did use the text bb tags. I will try again below:

This time I only tried it with two records. If I can understand the concept I can reproduce the results for the others. The text in red is suppose to be an interger. The other two black and green are strings. I am trying to get the text that is red to save to a interger so I can use it in a future code that will determine if this interger is less than zero than it will perform another function.

To bumsfeld, yeah this is my text. I am trying to get it to save to variables so I don't have to read through all of it. I actually have 21 of these wonderful files 2 times a week to read through and then post to a website. I am trying to automate it a little, because currently it puts me to sleep. I would like something more challenging than reading text files and posting them to the internet.

[TEX] 
  PSS(R)MUST  9.2   -- Managing and Utilizing System Transmission --  MON, SEP 28 2009  15:12
 2008 FRCC LFDB - 90% LOAD
 2009 SUMMER BASE
Case.File   C:\HourlyATC\ATC090928\OPCASE21.sav
Subsys.File C:\HourlyATC\subsystem.sub
Monit.File  C:\HourlyATC\monitor.mon
Contin.File C:\HourlyATC\contingency.con
Exclud.File C:\HourlyATC\exclude.exc
 
 Study transfer level -     1000.0 MW. Total violations: 7
 First violation      -     -571.5 MW.
 
Study transfer. From FMPP_EXA            To FPL_IMA            . Transfer level -   1000.0 MW
 
 
 Violations report ordered by transfer capability. Total     7 violations
 
 
   FCITC       TDF     LODF <---------     Limiting constraint      ---------> <---------     Contingency description      ---------> Ncon    PreShift  Rating     PTDF IntBase FnlBase
  -571.5  -0.03039 -0.19893    [B]6106 I-STATE      230   6104 TENOROC      230 1[/B]  C:9100-9120D                                            446     -454.4  -437.0 -0.01716  -377.1  -367.3
                                                                                  Open   [B]9100 RECKER       230   9120 SELOSE       230 1[/B] 

 Study transfer level -     1000.0 MW. Total violations: 17
 First violation      -     -626.4 MW.
 
Study transfer. From FMPP_EXA            To PEF_IMA            . Transfer level -   1000.0 MW
 
 
 Violations report ordered by transfer capability. Total    17 violations
 
 
   FCITC       TDF     LODF <---------     Limiting constraint      ---------> <---------     Contingency description      ---------> Ncon    PreShift  Rating     PTDF IntBase FnlBase
  -626.4  -0.04873  0.30911    [B]6106 I-STATE      230   6104 TENOROC      230 1[/B]  C:  7890 OSCEOLA      230   9190 AGNES-RX     230 1     414     -467.5  -437.0 -0.04950  -377.1  -346.1
                                                                                  Open   [B]7890 OSCEOLA      230   9190 AGNES-RX     230 1[/B] 
 Study transfer level -     1000.0 MW. Total violations: 5
 First violation      -     -443.2 MW.
 
Study transfer. From FMPP_EXA            To TECO_IMA           . Transfer level -   1000.0 MW
 
 
 Violations report ordered by transfer capability. Total     5 violations
 
 
   FCITC       TDF     LODF <---------     Limiting constraint      ---------> <---------     Contingency description      ---------> Ncon    PreShift  Rating     PTDF IntBase FnlBase
  -443.2  -0.03919 -0.19893    6106 I-STATE      230   6104 TENOROC      230 1  C:9100-9120D                                            446     -454.4  -437.0 -0.02746  -377.1  -365.0
                                                                                  Open   9100 RECKER       230   9120 SELOSE       230 1
 
 Study transfer level -     1000.0 MW. Total violations: 6
 First violation      -     1145.8 MW.
 
Study transfer. From FPL_EXA             To FMPP_IMA           . Transfer level -   1000.0 MW
 
 
 Violations report ordered by transfer capability. Total     6 violations
 
 
   FCITC       TDF     LODF <---------     Limiting constraint      ---------> <---------     Contingency description      ---------> Ncon    PreShift  Rating     PTDF IntBase FnlBase
  1145.8  -0.11840  0.52227    8860 SO GIB-S     230   8900 B BEND       230 1  C:8500-8900                                             592     -613.3  -749.0 -0.09149  -368.8  -473.6
                                                                                  Open   8500 11TH AVE     230   8900 B BEND       230 1
 
 Study transfer level -     1000.0 MW. Total violations: 6
 First violation      -     1481.3 MW.
 
Study transfer. From PEF_EXA             To FMPP_IMA           . Transfer level -   1000.0 MW
 
 
 Violations report ordered by transfer capability. Total     6 violations
 
 
   FCITC       TDF     LODF <---------     Limiting constraint      ---------> <---------     Contingency description      ---------> Ncon    PreShift  Rating     PTDF IntBase FnlBase
  1481.3   0.09024  0.51643    2167 WINDERME     230   5701 SO WOOD      230 1  C:5353-5800                                             581      233.3   367.0  0.08419   150.0   274.7
                                                                                  Open   5352 CAN ISL      230   5800 OUCCITP1     230 1
 
 Study transfer level -     1000.0 MW. Total violations: 5
 First violation      -     1525.8 MW.
 
Study transfer. From TECO_EXA            To FMPP_IMA           . Transfer level -   1000.0 MW
 
 
 Violations report ordered by transfer capability. Total     5 violations
 
 
   FCITC       TDF     LODF <---------     Limiting constraint      ---------> <---------     Contingency description      ---------> Ncon    PreShift  Rating     PTDF IntBase FnlBase
  1525.8  -0.14795  0.44375    8000 SHELD        230   8370 JUNEAU       230 1  C:8700-8400                                             600     -571.3  -797.0 -0.12009  -405.1  -588.3
                                                                                  Open   8400 CHAPMAN      230   8700 GANNON       230 1
 
 Study transfer level -     1000.0 MW. Total violations: 6
 First violation      -     1268.3 MW.
 
Study transfer. From IPP_REL_EXA         To FMPP_IMA           . Transfer level -   1000.0 MW
 
 
 Violations report ordered by transfer capability. Total     6 violations
 
 
   FCITC       TDF     LODF <---------     Limiting constraint      ---------> <---------     Contingency description      ---------> Ncon    PreShift  Rating     PTDF IntBase FnlBase
  1268.3  -0.38320  0.92478     461 CAPE K       230   5703 IND RIV      230 2  C:   461 CAPE K       230   5703 IND RIV      230 1     360     -311.0  -797.0 -0.19986  -162.2  -415.7
                                                                                  Open    461 CAPE K       230   5703 IND RIV      230 1
 
 Study transfer level -     1000.0 MW. Total violations: 6
 First violation      -      681.1 MW.
 
Study transfer. From IPP_REL_EXA         To FPL_IMA            . Transfer level -   1000.0 MW
 
 
 Violations report ordered by transfer capability. Total     6 violations
 
 
   FCITC       TDF     LODF <---------     Limiting constraint      ---------> <---------     Contingency description      ---------> Ncon    PreShift  Rating     PTDF IntBase FnlBase
   681.1   0.16806 -0.23199     464 MALABAR      230    708 WYOMING      230 1  C:   275 MARTIN       500    476 POINSETT     500 1     149      516.7   631.2  0.09595   261.1   326.4
                                                                                  Open    275 MARTIN       500    476 POINSETT     500 1
 
 Study transfer level -     1000.0 MW. Total violations: 5
 First violation      -     -787.9 MW.
 
Study transfer. From IPP_REL_EXA         To PEF_IMA            . Transfer level -   1000.0 MW
 
 
 Violations report ordered by transfer capability. Total     5 violations
 
 
   FCITC       TDF     LODF <---------     Limiting constraint      ---------> <---------     Contingency description      ---------> Ncon    PreShift  Rating     PTDF IntBase FnlBase
  -787.9  -0.03316     -       6106 I-STATE      230   6104 TENOROC      230 1     Base Case                                                    -377.1  -351.0
 
 Study transfer level -     1000.0 MW. Total violations: 3
 First violation      -      569.5 MW.
 
Study transfer. From IPP_REL_EXA         To TECO_IMA           . Transfer level -   1000.0 MW
 
 
 Violations report ordered by transfer capability. Total     3 violations
 
 
   FCITC       TDF     LODF <---------     Limiting constraint      ---------> <---------     Contingency description      ---------> Ncon    PreShift  Rating     PTDF IntBase FnlBase
   569.5  -0.03573 -0.31618    6106 I-STATE      230   6104 TENOROC      230 1  C:  6105 CREWSLK      230   9050 PEBB         230 1     412     -416.7  -437.0 -0.01112  -377.1  -383.5
                                                                                  Open   6105 CREWSLK      230   9050 PEBB         230 1
[/TEX]

My question is :
How do you recognise the elements you want to keep :
Why is this in red and black

#
FCITC TDF LODF <--------- Limiting constraint ---------> <--------- Contingency description ---------> Ncon PreShift Rating PTDF IntBase FnlBase
#
-626.4 -0.04873 0.30911 6106 I-STATE 230 6104 TENOROC 230 1 C: 7890

And why is this one not
If you can tell us the elements that show which part is to be selected, then you'll nearly have the answer...
#
<--------- Limiting constraint ---------> <--------- Contingency description ---------> Ncon PreShift Rating PTDF IntBase FnlBase
#
-443.2 -0.03919 -0.19893 6106 I-STATE 230 6104 TENOROC 230 1 C:9100-9120D 446 -454.4 -437.0 -0.02746 -377.1 -365.0
#
Open 9100 RECKER 230 9120 SELOSE 230 1

Hi JICE
If you could see the text file. FCITC is one row above -626.4. The row starting with FCITC are the labels and the next row are the values. I need all the FCITC, Limiting Constraints and Contingency Descriptions. I had originally tried to label all of them but the bbcodes did not work. In this recent post I only labeled the first one. If I can figure out how to do that one I think I can figure out how to do the rest of them.
Thanks,
Joe

Are the fields separated with tabs, are their length fixed
I'd say fixed length
First (FCITC) is before 9th character
Limiting constraint is from 29th to 79 th
Contingency description is from 80th to 137th on the second line.
Is this ok ?
I'd do something like this

noline=0
for line in open("fcitc.txt"):
    if noline==1:
        fcitc=line[:9].strip()
        limConst=line[29:79].strip()
        noline+=1
    elif noline==2:
        contDesc=line.strip()
        print fcitc
        print limConst
        print contDesc
        noline=0
    if "FCITC" in line:
        noline+=1

Yes the lengths are fixed. I think this will work but I need to work with it more. How does this determine the row # of FCITC? The code seems to set No line to 1. Is this saying that the FCITC is located at line 1 and that no line +=1 would be the following line where the values are located? Is this the same as noline==2? Like I said I have to try this code tomorrow maybe I will be able to answer these questions on my own. Thanks again.
Joe

How does this determine the row # of FCITC?

Here :

if "FCITC" in line:
        noline+=1

The code seems to set No line to 1. Is this saying that the FCITC is located at line 1 and that no line +=1 would be the following line where the values are located? Is this the same as noline==2?

The idea is to say :
when i see a line with FCITC in it, i increase the number (i named it noline but it may not be the best name... You can choose noLineRelativelyToTheHeaderLine ;-) )
If this number is 1, i load fcitc and limit constraint in variables and i increase the number.
If this number is 2, i load the Contingency description in another variable (i take the whole line and strip it as there is nothing else on this line) and set the number to 0 so that every other line is ignored until FCITC is found again.

commented: Good start. It brought me closer to feeling I understood what the OP wants to do. +0

jice's solution looks good to me, unless you want only a slice of the second data line and want to convert the FCITC string into an integer. Here it is with a couple of minor changes to do that.

noline=0
for line in open("fcitc.txt"):
    if noline==1:
        fcitc=line[:9].strip()
        intFCITC = int(float(fcitc)) #OP wants this to be integer.
        limConst=line[29:79].strip()
        noline+=1
    elif noline==2:
        contDesc=line[90:137].strip() #Slice from line 2. Don't want entire line.
        print intFCITC
        print limConst
        print contDesc
        noline=0
    if "FCITC" in line:
        noline+=1

Thanks to both of you. I do need it as an interger, so the last posting will also be very helpful.
Joe

I have one more quick question. In the above text document I have many transfers the first one is FMPP to FPL, the second one is FMPP ro PEF. If I wanted to determine if FMPP to PEF's FTITC value is > 0, how do I determine what variable that paticular FTITC was assign to? It looks as though all of the FCITC Values overwrite the intFCITC value. Is there a way to have intFCITC increment so that intFCITC1 would be FMPP to FPL, intFCITC2 would be FMPP to PEF and intFCITC3 would be FMPP to TECO?
Thanks,
Joe

Instead of trying to make up new incremented variable names on the fly, you can create an empty list and append each intFCITC value to it. The elements of a list are sequenced in the order in which they were appended and can be referred to by index. The first element appended to the list has index of zero.

noline=0
intFCITC_list = [] #Empty list where we will put all values of intFCITC
for line in open("fcitc.txt"):
    if noline==1:
        fcitc=line[:9].strip()
        intFCITC = int(float(fcitc)) #OP wants this to be integer.
        intFCITC_list.append(intFCITC)
        limConst=line[29:79].strip()
        noline+=1
    elif noline==2:
        contDesc=line[90:137].strip() #Added subscripts. Don't want entire line.
        print fcitc
        print limConst
        print contDesc
        noline=0
    if "FCITC" in line:
        noline+=1
print "\nList of intFCITC values:" #All the intFCITC values should be in intFCITC_list
print intFCITC_list

#Refer to any element by its index
print "intFCITC_list[0] = ", intFCITC_list[0] #the first one is FMPP to FPL
print "intFCITC_list[1] = ", intFCITC_list[1] #the second one is FMPP ro PEF
print "intFCITC_list[2] = ", intFCITC_list[2] #FMPP to TECO?

Thank you very much. I probably have to study that command a little but that should work.
Thanks again,
Joe

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.