wxpython:我们如何在使用 textcontrol.GetValue() 时从字符串中删除空字节 [英] wxpython: How do we remove null byte from string when using textcontrol.GetValue()

查看:31
本文介绍了wxpython:我们如何在使用 textcontrol.GetValue() 时从字符串中删除空字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目标:使用两个文本控件框,一个作为输入,一个作为输出然而,该过程中还有一个额外的步骤,可能会因为 textcontrol.GetValue() 返回空字节而失败

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

所以说我有

self.tc1 = wx.TextCtrl(panel)

self.tc2 = wx.TextCtrl(panel)

然后我去做

cmd = self.tc1.GetValue()

如何排除字符串 cmd 的最后一个字符(或任何空字节)

How do I exclude last character of string cmd (or any null byte)

输出:

TypeError: execv() 参数 1 必须是没有 NULL 字节的编码字符串,而不是 str

TypeError: execv() argument 1 must be encoded string without NULL bytes, not str

推荐答案

刚刚想通了,

我不得不把它改成

cmd = self.tc1.GetValue().encode('ascii')

这篇关于wxpython:我们如何在使用 textcontrol.GetValue() 时从字符串中删除空字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆