我从标题中知道您可能认为这是重复的,但事实并非如此。
for id,row in enumerate(rows):
columns = row.findall("td")
teamName = columns[0].find("a").text, # Lag
playedGames = columns[1].text, # S
wins = columns[2].text,
draw = columns[3].text,
lost = columns[4].text,
dif = columns[6].text, # GM-IM
points = columns[7].text, # P - last column
dict[divisionName].update({id :{"teamName":teamName, "playedGames":playedGames, "wins":wins, "draw":draw, "lost":lost, "dif":dif, "points":points }})
这就是我的 Python 代码的样子。大多数代码已删除,但基本上我是从网站中提取一些信息。我将信息保存为字典。当我打印字典时,每个值周围都有一个括号 ["blbal"],这会导致我的 Iphone 应用程序出现问题。我知道我可以将变量转换为字符串,但我想知道是否有办法直接将信息作为字符串获取。
最佳答案
看起来你在列表中有一个字符串:
["blbal"]
要获取字符串,只需索引 l = ["blbal"]
print(l[0]) -> "blbal"
。
如果是字符串使用str.strip
'["blbal"]'.strip("[]")
或切片'["blbal "]'[1:-1]
如果它们始终存在。
关于python - 如何从python字符串中删除括号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29459008/