字典在给定数量的字符后有换行符

问题描述

我使用 pyshp 库来检索形状的坐标。

sf = shapefile.Reader(r"{}".format(boundary_file))
shapes = sf.shapes()
fields = sf.fields
records = sf.records()
for record in records:
    if record['NAME'] in cities_list:
        city = record['NAME']
        s = sf.shape(record_id)
        geom = s.__geo_interface__
        geom_list = []
            for dict in geom:
                if dict == "coordinates":
                    coord_dict = geom[dict]
                    coords = coord_dict[0]
                        for pairs in coords:
                            geom_list.append(pairs)

然后我需要根据'geom' dict 中的坐标创建一个字符串。 我使用的功能

def listToString(s):
    # initialize an empty string
    str1 = ""

    # traverse in the string
    for ele in s:
        str1 += "'{}',".format(ele)

    # return string
    return str1

我进一步处理字符串以删除除坐标之外的任何其他字符。 我的问题是存在一个我无法删除的换行符。 打印 print(listToString(geom_list )) 时,我注意到在特定数量的字符后有一个换行符

enter image description here

这是它在记事本++中的样子。

我想删除换行符并在一个字符串中打印坐标列表。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...