0

So, I’m using Telnetlib with Python 3 to try and create a software replay station, and I’m trying to modify one of the telnet commands to change the time code based on a variable, but I keep getting a syntax error since the only way I can get it to work is encoding the command as bytes

TC=5 #variable is changed by the GUI
session.write(b”play: timecode: 00:00:0”TC”;00 \nc”

Any idea how to format this with the proper syntax

Part 2: Here's the scale box I'm trying to use to modify

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)

which then references this in the support script

1 Answers1

0

Create string and later encode it to bytes

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() )

It string you have to use \\ to get \ in bytes

furas
  • 134,197
  • 12
  • 106
  • 148
  • Finally got back to my PC, I made those changes to the script with the correct variable (testguiPAGE_support.Ptime) as it references another support script and I get the following error `File "E:\Device Folders\Desktop\Rplay\Outputs\testgui.py", line 70, in text = "goto: timecode: -00:00:0" + str(testguiPAGE_support.Ptime) + ";00 \\nc" AttributeError: module 'testguiPAGE_support' has no attribute 'Ptime'` – corneredphoton Jul 21 '19 at 17:38
  • it seems you use wrong variable. It doesn't exists in this place. Maybe you created it in function - as local variable - so now it doesn't exist. – furas Jul 21 '19 at 17:53
  • I just added a part 2 that should help – corneredphoton Jul 21 '19 at 17:59
  • create new question on new page and put more code. This part of code is not enough. And shows where do you create variable `testguiPAGE_support.Ptime` and where do you use `str(testguiPAGE_support.Ptime)` – furas Jul 21 '19 at 18:03