问题
Objective: Use two textcontrol boxes, one as an input and one as an output However there is an additional step in the process, which fails likely because textcontrol.GetValue() returns null byte in addition
So say I have
self.tc1 = wx.TextCtrl(panel)
self.tc2 = wx.TextCtrl(panel)
and I go about it
cmd = self.tc1.GetValue()
How do I exclude last character of string cmd (or any null byte)
Output:
TypeError: execv() argument 1 must be encoded string without NULL bytes, not str
回答1:
Just figured it out,
I had to change it to
cmd = self.tc1.GetValue().encode('ascii')
回答2:
You simply use str.strip.
>>> foo = "bar\n"
>>> foo
'bar\n'
>>> foo.strip()
'bar'
Note this also removes any leading and trailing whitespace.
来源:https://stackoverflow.com/questions/15203106/wxpython-how-do-we-remove-null-byte-from-string-when-using-textcontrol-getvalue