使用Python分隔字段内的逗号分隔文本

|| 我目前正在尝试使用Python将表转换为RDF,并将每个单元格中的值附加到URL的末尾(例如E00变为statistics.data.gov.uk/id/statistical-geography/E00)。 我可以使用脚本对包含单个值的单元格执行此操作。
FirstCode = row[11]

if row[11] != \'\':

RDF = RDF + \'<http://statistics.data.gov.uk/id/statistical-geography/\' + FirstCode + \'>.\\n\'
数据库中的一个字段包含多个以逗号分隔的值。 因此,上面的代码将返回附加到URL的所有代码 例如
http://statistics.data.gov.uk/id/statistical-geography/E00,W00,S00
而我希望它返回三个值
statistics.data.gov.uk/id/statistical-geography/E00
statistics.data.gov.uk/id/statistical-geography/W00
statistics.data.gov.uk/id/statistical-geography/S00
是否有一些代码可以将我分开?     
已邀请:
是的,有
split
方法。
FirstCode.split(\",\")
将返回类似
(E00, W00, S00)
的列表 然后,您可以遍历列表中的项目:
 for i in FirstCode.split(\",\"):
      print i
将打印出: E00 W00 S00 此页面还有一些其他有用的字符串函数     
for i in FirstCode.split(\',\'):
    RDF = RDF + \'<http://statistics.data.gov.uk/id/statistical-geography/\' + i + \'>.\\n\'
    

要回复问题请先登录注册