如何在 session.write 中使用变量
How to use a variable in session.write
所以,我正在使用带有 Python 3 的 Telnetlib 来尝试创建一个软件重播站,并且我正在尝试修改一个 telnet 命令以根据变量更改时间码,但是我一直收到语法错误,因为我可以让它工作的唯一方法是将命令编码为 bytes
TC=5 #variable is changed by the GUI
session.write(b”play: timecode: 00:00:0”TC”;00 \nc”
知道如何使用正确的语法对其进行格式化吗
第 2 部分:这是我试图用来修改的比例框
self.IRpreroll = tk.Scale(top, from_=0.0, to=10.0)
self.IRpreroll.place(relx=0.659, rely=0.143, relwidth=0.317, relheight=0.0, height=59, bordermode='ignore')
self.IRpreroll.configure(activebackground="#ececec")
self.IRpreroll.configure(background="#282828")
self.IRpreroll.configure(font="TkTextFont")
self.IRpreroll.configure(foreground="#828282")
self.IRpreroll.configure(highlightbackground="#d9d9d9")
self.IRpreroll.configure(highlightcolor="black")
self.IRpreroll.configure(label="preroll time")
self.IRpreroll.configure(orient="horizontal")
self.IRpreroll.configure(troughcolor="#828282")
self.IRpreroll.configure(variable=testguiPAGE_support.Ptime)
然后在支持脚本中引用它
创建字符串,然后将其编码为字节
TC = 5
text = "play: timecode: 00:00:0" + str(TC) + ";00 \nc"
# or
text = "play: timecode: 00:00:0{};00 \nc".format(TC)
# or
text = f"play: timecode: 00:00:0{TC};00 \nc" # Python 3.6+
session.write( text.encode() )
它的字符串你必须使用 \
才能得到 \
以字节为单位
所以,我正在使用带有 Python 3 的 Telnetlib 来尝试创建一个软件重播站,并且我正在尝试修改一个 telnet 命令以根据变量更改时间码,但是我一直收到语法错误,因为我可以让它工作的唯一方法是将命令编码为 bytes
TC=5 #variable is changed by the GUI
session.write(b”play: timecode: 00:00:0”TC”;00 \nc”
知道如何使用正确的语法对其进行格式化吗
第 2 部分:这是我试图用来修改的比例框
self.IRpreroll = tk.Scale(top, from_=0.0, to=10.0)
self.IRpreroll.place(relx=0.659, rely=0.143, relwidth=0.317, relheight=0.0, height=59, bordermode='ignore')
self.IRpreroll.configure(activebackground="#ececec")
self.IRpreroll.configure(background="#282828")
self.IRpreroll.configure(font="TkTextFont")
self.IRpreroll.configure(foreground="#828282")
self.IRpreroll.configure(highlightbackground="#d9d9d9")
self.IRpreroll.configure(highlightcolor="black")
self.IRpreroll.configure(label="preroll time")
self.IRpreroll.configure(orient="horizontal")
self.IRpreroll.configure(troughcolor="#828282")
self.IRpreroll.configure(variable=testguiPAGE_support.Ptime)
然后在支持脚本中引用它
创建字符串,然后将其编码为字节
TC = 5
text = "play: timecode: 00:00:0" + str(TC) + ";00 \nc"
# or
text = "play: timecode: 00:00:0{};00 \nc".format(TC)
# or
text = f"play: timecode: 00:00:0{TC};00 \nc" # Python 3.6+
session.write( text.encode() )
它的字符串你必须使用 \
才能得到 \
以字节为单位