LibreOffice python宏在python控制台发出相同命令时出错

2024-09-30 20:23:02 发布

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

我们正在尝试将一个字符串从一个计算表中的单元格写入蓝牙序列。你知道吗

BT连接正常。
使用后:“sudo rfcomm bind 7 1”
我们可以用cutecom发送字符串。你知道吗

在python命令行中,这同样有效:

f1 = open("/dev/rfcomm7", "a")
f1.write("noot")
f1.flush()
f1.close()

“noot”由arduino上的HC-05 BT装置接收并显示在显示屏上。你知道吗

但是,从LibreOffice Calc运行以下宏会引发错误:

com.sun.star.uno.RuntimeExceptionError during invoking function writetofile in module file:///home/###/.config/libreoffice/4/user/Scripts/python/writeToSer.py (: [Errno 29] Illegal seek /home/###/.config/libreoffice/4/user/Scripts/python/writeToSer.py:17 in function writetofile() [f = open("/dev/rfcomm7", "a")] /usr/lib/libreoffice/program/pythonscript.py:870 in function invoke() [ret = self.func( *args )] )

计算中的宏:

import uno

def writetofile(*args):
    oDoc = XSCRIPTCONTEXT.getDocument()
    oSheet = oDoc.CurrentController.ActiveSheet
    oCell1 = oSheet.getCellByPosition(2, 80)
    shNumber = oCell1.String

    f2 = open("/home/###/pythonoefeningen/test.txt", "a")  
    f2.write(shNumber)
    f2.write("\n")
    f2.flush()
    f2.close()

    f = open("/dev/rfcomm7", "a")
    f.write("piet")  # shNumber)
    f.flush()
    f.close()

添加f2部分是为了确认上面的部分从电子表格中获取值并输出到文件。(确实如此)。 错误出现在以下行:f=open(“/dev/rfcomm7”,“a”)

谁能解释命令行和宏之间的行为差异。当然,你也可以提出一个解决方案。你知道吗

操作系统:linux mint 18

干杯


Tags: inpydevhomecloselibreofficefunctionopen