代码之家  ›  专栏  ›  技术社区  ›  Marcus Müller

python3.7.1:`10**3.5`:无法将字符串转换为float:3.5

  •  5
  • Marcus Müller  · 技术社区  · 6 年前

    我真的很困惑为什么会发生在我身上:

    Python 3.7.1 (default, Nov  5 2018, 14:07:04) 
    Type 'copyright', 'credits' or 'license' for more information
    IPython 6.4.0 -- An enhanced Interactive Python. Type '?' for help.
    
    In [1]: 10**3.5
    ValueError: could not convert string to float: 3.5
    

    有人能发光吗?如您所见,这是一个简单的输入,我认为它是一个浮点文字。

    我试过消除ipython的复杂性,并以隔离模式运行,但仍然:

    python3 -I -c "float('3.5')"
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
    ValueError: could not convert string to float: '3.5'
    

    我的蟒蛇3.7断了,我的理解断了,还是我在看什么?

    我通过将显示的代码放入一个文件中并进行十六进制转储来排除编码问题。它是干净的ASCII码,就像它应该的那样,带有 0x2e 一个点,和一个 0x0a 作为行尾:

    xxd testfile.py
    00000000: 332e 350a                                3.5.
    python3 -I testfile.py
    ValueError: could not convert string to float: 3.5
    

    操作系统:使用16 GB RAM的x86_64上的Fedora29。

    1 回复  |  直到 6 年前
        1
  •  1
  •   Marcus Müller    6 年前

    这个问题是由Fedora在没有我的交互的情况下进行glibc更新引起的。

    对gdb的扩展程序than应该进行的调查显示libc功能被错误地调用。

    所以我重新启动了。问题似乎解决了。