python程序调试题_关于python程序调试问题,一个文件计算的问题
那位大神幫小弟看下這段代碼有什么需要改進的沒有。程序要求為:程序主要內容是:大地坐標經緯度的格式轉換問題,例如120°30′30″轉換為120.50833333°,并且可以互換,這樣的程序。...
那位大神幫小弟看下這段代碼有什么需要改進的沒有。
程序要求為:
程序主要內容是 :大地坐標經緯度的格式轉換問題,例如120°30′30″ 轉換為120.50833333° ,并且可以互換, 這樣的程序。
具體實現為:度分秒與十進制的度 單個坐標互換,而且最重要的是可以調用本地的txt文件批量轉換,并保存成txt文檔。
公式:
1.度分秒轉換成十進制度公式:
例如 原數據 a°b′c″
要得到的數據為: {a+[(b+c/60)/60]}°
2.十進制度轉換成度分秒公式:
例如 原數據 A.B°
要得到的數據為: A° [取整(B*60)]′ {[B*60-取整(B*60)]*60}″
具體代碼為:
from __future__ import division
import string
import math
def transferDuFenMiao(fileContentList):
changedList = []
for item in fileContentList:
print item
gpsList=str(item).split("'")
print gpsList
if len(gpsList) < 3:
print "data item is not corrct"
else:
du = gpsList[0]
print du
fen = gpsList[1]
print fen
miao = gpsList[2]
print miao
#{a+[(b+c/60)/60]}°
print string.atof(miao)
print string.atof(fen)/60
print (string.atof(miao)+string.atof(fen)/60)/60
data = string.atof(du) +(string.atof(miao)+string.atof(fen)/60)/60
print data
changedList.append(data)
return changedList
#120.50833333°
def transferDecimal(fileContentList):
changedList = []
for i in fileContentList:
gpsList = str(i).split(".")
if len(gpsList) != 2:
print "data i is not corrct"
else:
a = gpsList[0]
b = gpsList[1]
#A° [取整(B*60)]′ {[B*60-取整(B*60)]*60}″
du = gpsList[0]
fen = math.ceil((string.atof(gpsList[1])*60)/60)
miao = (string.atof(gpsList[1])*60-fen)*60
data = du+"'"+str(fen)+"'"+str(miao)+"'"
changedList.append(data)
return changedList
def readFile(fileName):
print "begin read file"
fp=open(fileName)
arr=[]
for lines in fp.readlines():
#lines=lines.replace("\n","").split(",")
print lines
arr.append(lines)
fp.close()
return arr
def writeFile(toBeWrittenList,fileName):
fl=open(fileName, 'w')
for i in toBeWrittenList:
fl.write(str(i))
fl.write("\n")
fl.close()
def main():
print "please choose your model,1:present du-fen-miao model,2:present decimal model"
flag = input()
print "please input the file you want fo parse"
fileName = raw_input()
print flag
print fileName
arrayList = readFile(fileName)
print "here"
if flag == 1:
print "begin tranfer based on du_fen_miao"
writeFile(transferDuFenMiao(arrayList),"output1.txt")
elif flag == 2:
print "begin transfer based on decimal"
writeFile(transferDecimal(arrayList),"output2.txt")
if __name__ == '__main__':
main()
展開
總結
以上是生活随笔為你收集整理的python程序调试题_关于python程序调试问题,一个文件计算的问题的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: three.js加载3d模型_基于Web
- 下一篇: 微单反相机(最好的微单相机排行)
