简体   繁体   English

python:stringarray到格式化的字符串

[英]python: stringarray to formatted string

I'm trying to create a text from an array for creating a kml using this example , in the following lines: 我正在尝试使用此示例从数组创建用于创建kml的文本,如下所示:

KML.coordinates(
              "146.825,12.233,400 "
              "146.820,12.222,400 "
              "146.812,12.212,400 "
              "146.796,12.209,400 "
              "146.788,12.205,400"
            )

I have this coordinates in an array already as strings like this: 我在数组中的坐标已经像这样的字符串:

myCoords[0]: '146.825,12.233,400'
myCoords[1]: '146.820,12.222,400'
...

but if I give myCoords to KML.coordinates , i'll get a blob without new lines and with [] enclosing it. 但是如果我将myCoords交给KML.coordinates ,我会得到一个没有新行的blob,并用[] KML.coordinates起来。

I can use ', '.join(myCoords) to remove the [] , but it still a blob without new lines. 我可以使用', '.join(myCoords)删除[] ,但它仍然是一个没有新行的blob。 How can I do this? 我怎样才能做到这一点?

Thanks! 谢谢!

The example uses space separated data; 该示例使用空格分隔数据; the string literals have newlines between them, but Python joins those together. 字符串文字在它们之间有新行,但Python将它们连接在一起。

In any case, you can use ' '.join(myCoords) to join your coordinates in the same manner as that example. 在任何情况下,您都可以使用' '.join(myCoords)以与该示例相同的方式连接坐标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM