[Python] Why does np.fromfile fail when reading from a pipe?

Discussão em 'Python' iniciado por Stack, Abril 27, 2025.

  1. Stack

    Stack Membro Participativo

    In a Python script, I've written:

    # etc. etc.
    input_file = args.input_file_path or sys.stdin
    arr = numpy.fromfile(input_file, dtype=numpy.dtype('f32'))


    when I run the script, I get:

    $ cat nums.fp32.bin | ./myscript
    File "./myscript", line 123, in main
    arr = numpy.fromfile(input_file, dtype=numpy.dtype('f32'))
    OSError: obtaining file position failed


    why does NumPy need the file position? And - can I circumvent this somehow?

    Continue reading...

Compartilhe esta Página