简体   繁体   English

从字符串中提取科学计数法

[英]Extracting scientific notation from a string

I am trying to extract scientific notation from strings like: 我正在尝试从类似以下的字符串中提取科学符号:

`#DataCGSConversionFactor[0] = 1.0051900924519e-29`

Unfortunately because of the first 0 that isn't a part of the number I want, the other solutions I have tried don't work, giving: 不幸的是,由于前0不是我想要的数字的一部分,我尝试过的其他解决方案不起作用,给出:

ValueError: invalid literal for float(): 0]

Thanks in advance. 提前致谢。

For the string you show, 对于您显示的字符串,

x = "#DataCGSConversionFactor[0] = 1.0051900924519e-29"

f = float(x.split()[-1])    # split at spaces, take last item, and cast to a float

print f, type(f)
# 1.0051900924519e-29, float

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM