此代码产生了以下列表:
section[0:1]
这将导致以下元素:
[开始:(81979.67599999905 432187.33199999854)结束:(81980.92700000107 432188.0320000015)]
如何访问第一行的第一和第二个元素,即 81979.67599999905和 432187.33199999854。
type(section)
是一个列表
答案 0 :(得分:0)
您应该能够将结果强制转换为re
,然后使用import re
section_str = 'start:(81979.67599999905 432187.33199999854)end:(81980.92700000107 432188.0320000015)'
# Replace the last line by the next one
#section_str = str(section[0:1])
r = re.compile('start:\((.*?)\)end:')
m = r.search(section_str)
if m:
result = m.group(1)
print(result.split(' ')[0])
print(result.split(' ')[1])
包:
81979.67599999905
432187.33199999854
输出:
db2cmd -i -c FOR /F "usebackq skip=3 tokens=4" %%G IN ("aliasname.txt") DO DB2 UNCATALOG SYSTEM DATABASE %%G
答案 1 :(得分:0)
section[0:1]
返回1个元素的列表,因此更好的方法是先通过section[0]
来访问此元素,
假设
[start:(81979.67599999905 432187.33199999854)end:(81980.92700000107 432188.0320000015)]
是一个字符串,您可以尝试:
first = a.split('(')[1].split(' ')[0]
second = a.split('(')[1].split(' ')[1].split(')')[0]
输出:
>>> first
'81979.67599999905'
>>> second
'432187.33199999854'