删除字符串拆分连接Python中间的多余空格 [英] Remove extra spaces in middle of string split join Python

查看:211
本文介绍了删除字符串拆分连接Python中间的多余空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下字符串迫使我的Python脚本退出:

I have the following string which forces my Python script to quit:

"625             625 QUAIL DR UNIT B"

我需要删除字符串中间的多余空格,因此我尝试使用以下拆分连接脚本:

I need to delete the extra spaces in the middle of the string so I am trying to use the following split join script:

import arcgisscripting
import logging 
logger = logging.getLogger()

gp = arcgisscripting.create(9.3)
gp.OverWriteOutput = True

gp.Workspace = "C:\ZP4"
fcs = gp.ListWorkspaces("*","Folder")

for fc in fcs:

    print fc
    rows = gp.UpdateCursor(fc + "//Parcels.shp")
    row = rows.Next()
    while row:
        Name = row.GetValue('SIT_FULL_S').join(s.split())
        print Name
        row.SetValue('SIT_FULL_S', Name)
        rows.updateRow(row)
        row = rows.Next()
    del row
    del rows

推荐答案

您的源代码和您的错误不匹配,错误状态是您未定义变量SIT_FULL_S.

Your source code and your error do not match, the error states you didn't define the variable SIT_FULL_S.

我猜您想要的是:

Name = ' '.join(row.GetValue('SIT_FULL_S').split())

这篇关于删除字符串拆分连接Python中间的多余空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆