为什么这个while循环只执行第一个循环?

时间:2018-06-18 13:18:13

标签: python-3.x for-loop while-loop

我试图从起重机臂的风速数据中产生一些机械应力信息,当它在0到90度之间时,每个角度的数据都保存在它自己的文件中。当我只做一个文件/角度时,我的脚本运行正常,但是当我尝试使用任何类型的循环来执行所有角度时,它将创建文件,但只有第一个文件中有任何数据。我是初学者,对Python不太了解,所以我希望有人能发现一些我错过的简单内容。我已经包含了源数据的简短示例文件:Windspeed source file - cut down

import math
file = open("C:/Users/Jacob/Desktop/BOM Data/HD01D_Data_074272_999999999523840.txt", 'r')

boomDirection = 0
vaneSpeed = 120
maxShear = 75.97043478
maxVonMises = 500.0216811

while boomDirection < 91:
    data_file = open("Bolt Stress - " + str(boomDirection) + " Degrees.csv", 'w')
    line = file.readline()
    line = file.readline()
    while line != '':
        try:
            if len(line.split(','))>1:                                      
                windSpeedHigh = int(line.split(',')[19])
                windSpeedLow = int(line.split(',')[22])
                windDirection = int(line.split(',')[14])
                relSpeedHigh = math.sin(math.radians((90-(boomDirection - windDirection))))*windSpeedHigh
                relSpeedLow = math.sin(math.radians((90-(boomDirection - windDirection))))*windSpeedLow
                VonMisesHigh = (maxVonMises/vaneSpeed)* relSpeedHigh
                VonMisesLow = (maxVonMises/vaneSpeed)* relSpeedLow
                data_file.write(str(round(VonMisesHigh,1)) + ('\n'))
                data_file.write(str(round(VonMisesLow,1)) + ('\n'))
        except ValueError:
            pass
        line = file.readline()
    data_file.close()
    boomDirection = boomDirection + 1

0 个答案:

没有答案