我目前正在尝试使用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有没有什么代码可以让我把它们分开?
发布于 2011-05-21 04:53:43
是的,有split方法。
FirstCode.split(",")将返回一个类似于(E00, W00, S00)的列表
然后,您可以迭代列表中的项:
for i in FirstCode.split(","):
print i将打印出来: E00 W00 S00
This page还有其他一些有用的字符串函数
发布于 2011-05-21 04:54:32
for i in FirstCode.split(','):
RDF = RDF + '<http://statistics.data.gov.uk/id/statistical-geography/' + i + '>.\n'https://stackoverflow.com/questions/6077429
复制相似问题