0

I'm trying to print multiple lines (in this case 2 lines) from a *.txt file with Python.

I want to print both "if" in the same line but I can't.

Code:

import os
import sys

path = #sys.argv[1]
InputText1 = '#  Class ID     Number of Cells    Class Name'
InputText2 = '# Means'


for file in os.listdir(path):
    #print file [13:15]
    #if file.endswith("*.gsg"):
        #print os.path.join(path,file)
    with open(os.path.join(path,file), "r") as input:
        for line in input:
            if InputText1 in line:
                #print(line)
                print str(file)[0:1].strip() + "," + str(next(input)[:10].strip()) + ","
            if InputText2 in line:
                #print(line)
                print next(input).strip()

Results:

1,1,
5.004188e-001
1,2,
5.822568e-001
1,3,
6.339202e-001
1,4,
6.711560e-001
1,5,
6.976744e-001
Jongware
  • 22,200
  • 8
  • 54
  • 100
jpdelped
  • 1
  • 1

0 Answers0