当前位置: 首页 > news >正文

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

我编了个小程序 读取文件数据,运行时总提示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 ]):     #根据单元来对应截面,然后求得等效截面

相关文章:

  • 【pycharm 教程】(一)安装和首次使用
  • 【Pycharm教程】(二)设置字体大小
  • 【Pycharm教程】(三)第一个代码Hello world!
  • 【PyCharm 教程】(四)显示行号
  • 【PyCharm 教程】(五)断点 调试
  • 【PyCharm 教程】(六)自定义文件模板
  • 【PyCharm 教程】(七)管理解释器及第三方模块、包
  • 【Bug-python】IndexError: list index out of range
  • 【深度学习:CNN】如何高效的通过BP算法来训练CNN
  • 【VC++DLL动态链接库编程】DLL动态链接库的原理讲解(2)
  • 【VC++DLL动态链接库编程】VC++静态库编译(3)
  • 【VC++DLL动态链接库编程】DLL动态链接库创建(4)
  • 【VC++DLL动态链接库编程】教程目录(1)
  • 【人脸检测】Adaboost+Haar目录
  • 【python】List与string转化--test_veh.py代码
  • 【技术性】Search知识
  • Bootstrap JS插件Alert源码分析
  • C++类中的特殊成员函数
  • Flex布局到底解决了什么问题
  • golang中接口赋值与方法集
  • MYSQL如何对数据进行自动化升级--以如果某数据表存在并且某字段不存在时则执行更新操作为例...
  • orm2 中文文档 3.1 模型属性
  • React的组件模式
  • SpiderData 2019年2月23日 DApp数据排行榜
  • Terraform入门 - 1. 安装Terraform
  • Vue 2.3、2.4 知识点小结
  • webpack入门学习手记(二)
  • 如何选择开源的机器学习框架?
  • 实战:基于Spring Boot快速开发RESTful风格API接口
  • 协程
  • 【干货分享】dos命令大全
  • CMake 入门1/5:基于阿里云 ECS搭建体验环境
  • 关于Kubernetes Dashboard漏洞CVE-2018-18264的修复公告
  • # Swust 12th acm 邀请赛# [ K ] 三角形判定 [题解]
  • #define MODIFY_REG(REG, CLEARMASK, SETMASK)
  • #微信小程序:微信小程序常见的配置传旨
  • (06)Hive——正则表达式
  • (k8s中)docker netty OOM问题记录
  • (Matalb分类预测)GA-BP遗传算法优化BP神经网络的多维分类预测
  • (pytorch进阶之路)扩散概率模型
  • (二)JAVA使用POI操作excel
  • (二)Pytorch快速搭建神经网络模型实现气温预测回归(代码+详细注解)
  • (附源码)springboot 个人网页的网站 毕业设计031623
  • (附源码)计算机毕业设计SSM教师教学质量评价系统
  • (附源码)小程序 交通违法举报系统 毕业设计 242045
  • (三)模仿学习-Action数据的模仿
  • (十二)springboot实战——SSE服务推送事件案例实现
  • (原創) 系統分析和系統設計有什麼差別? (OO)
  • (源码版)2024美国大学生数学建模E题财产保险的可持续模型详解思路+具体代码季节性时序预测SARIMA天气预测建模
  • (转)详解PHP处理密码的几种方式
  • (轉貼) VS2005 快捷键 (初級) (.NET) (Visual Studio)
  • .net core 3.0 linux,.NET Core 3.0 的新增功能
  • .Net 应用中使用dot trace进行性能诊断
  • .NET/C# 解压 Zip 文件时出现异常:System.IO.InvalidDataException: 找不到中央目录结尾记录。
  • .NET导入Excel数据