Python从命名pip获取数据

2024-10-02 14:26:01 发布

您现在位置:Python中文网/ 问答频道 /正文

如何从python3.5.3中的命名管道读取数据?在

管道的名称和位置是/tmp/shairport-sync-metadata,任何人都可以查看它,但只能由shairport-sync用户修改。 其他网站和问题都说要使用os.mkfifo("pipe-location"),但我得到了这个错误:

>>> import os
>>> os.mkfifo("/tmp/shairport-sync-metadata")

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    os.mkfifo("/tmp/shairport-sync-metadata")
FileExistsError: [Errno 17] File exists

有办法绕过这个问题吗?很抱歉问你这个问题。在


Tags: 用户名称管道os网站locationsync读取数据
1条回答
网友
1楼 · 发布于 2024-10-02 14:26:01

^{}用于创建fifo。使用^{}打开/读取已存在的fifo:

with open('/tmp/shairport-sync-metadata') as f:   # add `rb` for binary mode
    # line-by-line read
    for line in f:
        print(line)

    # f.read(1024)  # to read 1024 characters

相关问题 更多 >