Hi,
I am here with placing the Sample code for reading the and Input data mentioned.
Is there any best of reading the file?.
Thanks in advance
PSB
I am here with placing the Sample code for reading the and Input data mentioned.
Is there any best of reading the file?.
Thanks in advance
PSB
Code:
Sampple1.txt Rect 1 1 2 7 6 Rect 2 2 3 8 7 Rect 3 3 4 9 8 Tria 4 4 5 9 Pnt 1 0. 0. 0. Pnt 2 5. 0. 0. Pnt 3 10. 0. 0. Pnt 4 15. 0. 0. Pnt 5 20. 0. 0. Pnt 6 0. 5. 0. Pnt 7 5. 5. 0. Pnt 8 10. 5. 0. Pnt 9 15. 5. 0.
Code:
Sample.py def read_file_data(strFile): f = open(strFile,'r') pntIDDict = {} pntCoordDict = {} pntList = [] coordList = [] wireIDDict ={} while True: strTemp = f.readline() if len(strTemp)>=1: strTemp = strTemp[:(len(strTemp)-1)] if strTemp[:3]=='Pnt': pntID = int(strTemp[8:16]) coordList.append((float(strTemp[16:24]))) coordList.append((float(strTemp[24:32]))) coordList.append((float(strTemp[32:40]))) pntIDDict[pntID]=coordList coordList = [] elif (strTemp[:4]=='Rect' or strTemp[:4]=='Tria'): wireID = int(strTemp[8:16]) pntList.append((int(strTemp[16:24]))) pntList.append((int(strTemp[24:32]))) pntList.append((int(strTemp[32:40]))) if (strTemp[:4]=='Rect'): pntList.append((int(strTemp[40:48]))) wireIDDict[wireID]=pntList pntList = [] else: break f.close() return pntIDDict,wireIDDict if __name__ == '__main__': pntIDDict = {} wireIDDict = {} ntIDDict,wireIDDict = read_file_data ("c:\\Sample1.txt") print ntIDDict,wireIDDict
Comment