日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python程序调试题_关于python程序调试问题,一个文件计算的问题

發(fā)布時(shí)間:2023/12/2 python 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python程序调试题_关于python程序调试问题,一个文件计算的问题 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

那位大神幫小弟看下這段代碼有什么需要改進(jìn)的沒有。程序要求為:程序主要內(nèi)容是:大地坐標(biāo)經(jīng)緯度的格式轉(zhuǎn)換問題,例如120°30′30″轉(zhuǎn)換為120.50833333°,并且可以互換,這樣的程序。...

那位大神幫小弟看下這段代碼有什么需要改進(jìn)的沒有。

程序要求為:

程序主要內(nèi)容是 :大地坐標(biāo)經(jīng)緯度的格式轉(zhuǎn)換問題,例如120°30′30″ 轉(zhuǎn)換為120.50833333° ,并且可以互換, 這樣的程序。

具體實(shí)現(xiàn)為:度分秒與十進(jìn)制的度 單個(gè)坐標(biāo)互換,而且最重要的是可以調(diào)用本地的txt文件批量轉(zhuǎn)換,并保存成txt文檔。

公式:

1.度分秒轉(zhuǎn)換成十進(jìn)制度公式:

例如 原數(shù)據(jù) a°b′c″

要得到的數(shù)據(jù)為: {a+[(b+c/60)/60]}°

2.十進(jìn)制度轉(zhuǎn)換成度分秒公式:

例如 原數(shù)據(jù) A.B°

要得到的數(shù)據(jù)為: 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()

展開

總結(jié)

以上是生活随笔為你收集整理的python程序调试题_关于python程序调试问题,一个文件计算的问题的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。