在python项目中,我有大量的坐标(x,y值)列表:
>>> from pywinauto import Desktop, Application
>>> network_cpl = Application(backend="uia").start('control /name Microsoft.NetworkAndSharingCenter')
>>> network_cpl.process
9652
>>> dlg_desktop = Desktop(backend="uia")["Network and Sharing Center"]
>>> found_dlg = dlg_desktop.wrapper_object()
>>> found_dlg.process_id()
15520
要将其读取为las文件,我需要用空格将x y z分隔并返回:
Coordinates = [(144282.027, 523177.144), (144281.691, 523183.33), (144280.696, 523183.275), (144280.506, 523186.767), (144272.518, 523186.348), (144272.702, 523182.862), (144269.203, 523182.673), (144269.541, 523176.471), (144274.835, 523176.759), (144275.025, 523173.261), (144281.218, 523173.598), (144281.028, 523177.09), (144282.027, 523177.144)]
我只能以相反的方式在stackoverflow上看到答案:用空格分隔的文本文件-> python列表
答案 0 :(得分:2)
您可以执行以下操作:
coordinates = [(144282.027, 523177.144), (144281.691, 523183.33), (144280.696, 523183.275), (144280.506, 523186.767), (144272.518, 523186.348), (144272.702, 523182.862), (144269.203, 523182.673), (144269.541, 523176.471), (144274.835, 523176.759), (144275.025, 523173.261), (144281.218, 523173.598), (144281.028, 523177.09), (144282.027, 523177.144)]
lines = ['{} {} {}\n'.format(x, y, 0) for x, y in coordinates]
with open('output.txt', 'w') as outfile:
for line in lines:
outfile.write(line)
以上代码以以下格式将坐标写入output.txt
:
144282.027 523177.144 0
144281.691 523183.33 0
144280.696 523183.275 0
144280.506 523186.767 0
144272.518 523186.348 0
144272.702 523182.862 0
144269.203 523182.673 0
144269.541 523176.471 0
144274.835 523176.759 0
144275.025 523173.261 0
144281.218 523173.598 0
144281.028 523177.09 0
144282.027 523177.144 0