2024-10-02 08:17:27 发布
网友
例如,这里有一行“2020-08-12 13:45:04 0.86393%ContractWeber”,我需要在文本文件中“%ContractWeber”字符串之前提取9个字符。 所以,这里我的答案是“0.86393”。我不明白用Python怎么做?请帮忙
line = '2020-08-12 13:45:04 0.86393 %contrastWeber' position = line.index('%contrastWeber') if position >= 0: starting = position - 9 if starting < 0: starting = 0 ending = position print(line[starting : ending]) else: print('is not found')
相关问题 更多 >
编程相关推荐