有错误代码,只是借鉴以下编程思想

博主编写了一个Python程序用于读取文件数据,在运行过程中遇到IndexError异常,提示索引超出范围,尽管代码中已尝试避免此类错误。该程序涉及多个文件的读取和解析,包括对数据进行特定格式的处理。
我编了个小程序 读取文件数据,运行时总提示IndexError: list index out of range ,我仔细检查了,索引并没有越界啊,还有其他原因导致这个错误吗 代码太长了 贴出部分代码 希望大家帮忙看看 感激不尽    
Python code ?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
     file1 = open ( '%s'  %  mgt)     #从mgt文件中读取信息
     global  line1
     line1 = []
     global  line1num
     line1num = 0
     for  eachline  in  file1.readlines():
         line1.append(eachline)
         line1num + = 1      
     global  components
     components = []
     global  compnum
     compnum = 0
     i = 0
     cps = 0
     cpo = 0
     while  i<line1num:
         if  line1[i] = = '*MEMBER    ; Member' + '\n' :
             cps = i + 1
             break
         i + = 1
     cpt = cps
     if  cpt! = 0 :
         while  cpt<line1num:
             if  line1[cpt] = = '\n' :
                 cpo = cpt
                 break
             cpt + = 1
     j = 0
     while  cps<cpo:
         line1[cps] = line1[cps].strip()
         r = re. compile ( ',' )
         comdata = []
         comdata = r.split(line1[cps])
         components.append([])
         i = 0
         while  i< len (comdata):
             components[j].append(comdata[i])
             i + = 1
         j + = 1
         compnum + = 1
         cps + = 1
     for  each  in  components:
         each.pop( 1 )
     file7 = open ( '%s'  %  rcs1)     #从rcs文件中读取信息
     #此时line2不是全局变量
     line2 = []
     line2num = 0
     for  eachline  in  file7.readlines():
         line2.append(eachline)
         line2num + = 1
     file7.close()
     combeamnum = 0 
     line3 = [] 
     line3num = 0  
     line5 = []  
     line6 = []  
     line7 = [] 
     line8 = [] 
     i = 0
     while  i<line2num:
         if  line2[i].count( 'kN, m' )! = 0 :
             cb = i + 1
             break
         i + = 1    
     ct = cb     
     if  ct! = 0 :
         while  ct<line2num:
             if  line2[ct].count( '=' ) = = 3 :
                 line3.append(line2[ct])
                 line3num + = 1
             if  line2[ct].count( '=' ) = = 2 :
                 line3.append(line2[ct])
                 line3num + = 1
             if  line2[ct].count( '@' )! = 0 :
                 line3.append(line2[ct])
                 line3num + = 1    
             ct + = 1    
     i = 0
     while  i<line3num:
         line3[i] = line3[i].strip()
         line3[i + 1 ] = line3[i + 1 ].strip()
         line3[i + 2 ] = line3[i + 2 ].strip()
         line3[i + 3 ] = line3[i + 3 ].strip()
         line3[i + 4 ] = line3[i + 4 ].strip()
         line3[i + 5 ] = line3[i + 5 ].strip()
         r = re. compile ( ' *' )     #利用正则表达式,' *'对应' ','  ','   ','    '这一类
         line4data = []
         line4data1 = []
         line4data2 = []
         line4data3 = []
         line4data4 = []
         line4data5 = []
         line4data = r.split(line3[i])
         line4data1 = r.split(line3[i + 1 ])
         line4data2 = r.split(line3[i + 2 ])
         line4data3 = r.split(line3[i + 3 ])
         line4data4 = r.split(line3[i + 4 ])
         line4data5 = r.split(line3[i + 5 ])
         line4data[ 2 ] = line4data[ 2 ].strip()
         line4data[ 2 ] = line4data[ 2 ].rstrip( ',' )
         line4data[ 5 ] = line4data[ 5 ].strip()
         line5.append([ int (line4data[ 2 ])])
         line5[i].append( int (line4data[ 5 ]))
         line4data1[ 2 ] = line4data1[ 2 ].strip()
         line4data1[ 2 ] = line4data1[ 2 ].rstrip( ',' )
         line4data1[ 5 ] = line4data1[ 5 ].strip()
         line5.append([ float (line4data1[ 2 ])])
         line5[i + 1 ].append( float (line4data1[ 5 ]))
         line4data2[ 5 ] = line4data2[ 5 ].strip()
         line4data2[ 5 ] = line4data2[ 5 ].rstrip( ',' )
         line4data2[ 5 ] = 'HRB' + str ( int (line4data2[ 5 ]) / 1000 )
         line5.append([line4data2[ 5 ]])
         line4data3[ 5 ] = line4data3[ 5 ].strip()
         line4data3[ 6 ] = line4data3[ 6 ].strip()
         line4data3[ 6 ] = line4data3[ 6 ].split( '-' )
         line4data3[ 6 ][ 1 ] = line4data3[ 6 ][ 1 ].lstrip( 'd' )
         line4data3[ 10 ] = line4data3[ 10 ].strip()
         line4data3[ 11 ] = line4data3[ 11 ].strip()
         line4data3[ 11 ] = line4data3[ 11 ].split( '-' )
         line4data3[ 11 ][ 1 ] = line4data3[ 11 ][ 1 ].lstrip( 'd' )
         line5.append([ float (line4data3[ 5 ])])
         line5[i + 3 ].append( int (line4data3[ 6 ][ 0 ]))
         line5[i + 3 ].append( int (line4data3[ 6 ][ 1 ]))
         line5[i + 3 ].append( float (line4data3[ 10 ]))
         line5[i + 3 ].append( int (line4data3[ 11 ][ 0 ]))
         line5[i + 3 ].append( int (line4data3[ 11 ][ 1 ]))
         line4data4[ 5 ] = line4data4[ 5 ].strip()
         line4data4[ 6 ] = line4data4[ 6 ].strip()
         line4data4[ 6 ] = line4data4[ 6 ].split( '-' )
         line4data4[ 6 ][ 1 ] = line4data4[ 6 ][ 1 ].lstrip( 'd' )
         line4data4[ 10 ] = line4data4[ 10 ].strip()
         line4data4[ 11 ] = line4data4[ 11 ].strip()
         line4data4[ 11 ] = line4data4[ 11 ].split( '-' )
         line4data4[ 11 ][ 1 ] = line4data4[ 11 ][ 1 ].lstrip( 'd' )
         line5.append([ float (line4data4[ 5 ])])
         line5[i + 4 ].append( int (line4data4[ 6 ][ 0 ]))
         line5[i + 4 ].append( int (line4data4[ 6 ][ 1 ]))
         line5[i + 4 ].append( float (line4data4[ 10 ]))
         line5[i + 4 ].append( int (line4data4[ 11 ][ 0 ]))
         line5[i + 4 ].append( int (line4data4[ 11 ][ 1 ]))
         line4data5[ 5 ] = line4data5[ 5 ].strip()
         line4data5[ 6 ] = line4data5[ 6 ].strip()
         line4data5[ 6 ] = line4data5[ 6 ].split( '-' )
         line4data5[ 6 ][ 1 ] = line4data5[ 6 ][ 1 ].lstrip( 'd' )
         line4data5[ 10 ] = line4data5[ 10 ].strip()
         line4data5[ 11 ] = line4data5[ 11 ].strip()
         line4data5[ 11 ] = line4data5[ 11 ].split( '-' )
         line4data5[ 11 ][ 1 ] = line4data5[ 11 ][ 1 ].lstrip( 'd' )
         line5.append([ float (line4data5[ 5 ])])
         line5[i + 5 ].append( int (line4data5[ 6 ][ 0 ]))
         line5[i + 5 ].append( int (line4data5[ 6 ][ 1 ]))
         line5[i + 5 ].append( float (line4data5[ 10 ]))
         line5[i + 5 ].append( int (line4data5[ 11 ][ 0 ]))
         line5[i + 5 ].append( int (line4data5[ 11 ][ 1 ]))
         i + = 6
     i = 0
     j = 0
     while  j< len (line5):
         line6.append([])
         line6[i] = line5[j] + line5[j + 1 ] + line5[j + 2 ] + line5[j + 3 ]    
         line7.append([])
         line7[i] = line5[j] + line5[j + 1 ] + line5[j + 2 ] + line5[j + 4 ]
         line8.append([])
         line8[i] = line5[j] + line5[j + 1 ] + line5[j + 2 ] + line5[j + 5 ]
         combeamnum + = 1
         i + = 1
         j + = 6
         j = 0
     print  line6
     print  len (line6)
     print  combeamnum    
     print  components
     print  len (components)
     print  compnum
     while  j<combeamnum:
         if  section[ int (line6[j][ 1 ]) - 1 ][ 1 ] = = 'SB' :   
             B = float (line6[j][ 2 ])                    
             H = float (line6[j][ 3 ])
             if  B = = 0.1 :
                 B = 0.1001
             if  H = = 0.1 :
                 H = 0.1001
             k = 0 
             while  k<compnum:
                 if  int (components[k][ 0 ]) = = int (line6[j][ 0 ]):     #根据单元来对应截面,然后求得等效截面
                     if  len (components[k]) = = 1 :     #梁没有被分割
                         if  int (line6[j][ 5 ]) + int (line6[j][ 8 ])< int (line8[j][ 5 ]) + int (line8[j][ 8 ]):
....下面还很长 不贴出来了 运行后 结果是
[[ 1 1 0.25 0.5998 'HRB335' 0.000297 2 20 0.00029997 2 20 ], [ 2 1 0.25 0.598 'HRB335' 0.000501 2 20 0.0002997 2 20 ], [ 3 1 0.25 0.5998 'HRB335' 0.0005001 2 20 0.00029997 2 20 ], [ 4 1 0.25 0.5998 'HRB335' 0.0005001 2 20 0.0002997 2 20 ], [ 5 1 0.25 0.5998 'HRB335' 0.00050001 2 20 0.00040002 2 20 ], [ 6 1 0.25 0.5998 'HRB335' 0.0002997 2 20 0.0002997 2 20 ], [ 7 1 0.25 0.5998 'HRB335' 0.000297 2 20 0.0002997 2 20 ], [ 8 1 0.25 0.59998 'HRB335' 0.00998 3 20 0.00029997 2 20 ]]
8
8
[[ '1' ' 571' ' 572' ], [ '2' ' 603' ' 604' ], [ '3' ' 635' ' 636' ], [ '4' ' 673' ' 674' ], [ '5' ' 559' ' 560' ], [ '6' ' 201' ], [ '7' ' 213' ], [ '8' ' 661' ' 662' ], [ '9' ' 544' ' 546' ], [ '10' ' 227' ], [ '11' ' 239' ], [ '12' ' 648' ' 650' ], [ '13' ' 543' ' 545' ], [ '14' ' 583' ' 584' ], [ '15' ' 615' ' 616' ], [ '16' ' 647' ' 649' ], [ '17' ' 570' ' 569' ], [ '18' ' 558' ' 557' ], [ '19' ' 542' ' 541' ], [ '20' ' 574' ' 573' ], [ '21' ], [ '22' ' 548' ' 547' ]]
22
22
Exception  in  Tkinter callback
Traceback (most recent call last):
   File  "D:\Program Files\Python25\lib\lib-tk\Tkinter.py" , line  1403 in  __call__
     return  self .func( * args)
   File  "C:/Users/caizhen/Desktop/M2A0404调试.py" , line  9970 in  r5progress
     compbeamsecbar()
   File  "C:/Users/caizhen/Desktop/M2A0404调试.py" , line  1869 in  compbeamsecbar
     if  int (components[k][ 0 ]) = = int (line6[j][ 0 ]):     #根据单元来对应截面,然后求得等效截面
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值