python删除“下一行”字符(以\ x1b [1b)的形式出现

发布于 2025-02-05 03:25:32 字数 537 浏览 2 评论 0原文

我正在通过防火墙通过SSH与Paramiko一起提取输出。 输出是这样显示的:

l = ['Total active sessions : 0\r\x1b[1BActive TCP sessions   : 0\r\x1b[1BActive UDP sessions   : 0\r\x1b[1BActive ICMP sessions  : 0\r\x1b[1B']

我能够使用以下命令将列表分开

for i in l:
    i.splitlines()

['Total active sessions : 0', '\x1b[1BActive TCP sessions   : 0', '\x1b[1BActive UDP sessions   : 0', '\x1b[1BActive ICMP sessions  : 0', '\x1b[1B']

,在表中的所有元素中仍出现\ x1b [1b。我查找了字节字符,这似乎是一个“下一行”字符。无论哪种方式,如何将其从列表中的每个元素中删除?

I am pulling output with paramiko via ssh from a firewall.
The output is showing like this:

l = ['Total active sessions : 0\r\x1b[1BActive TCP sessions   : 0\r\x1b[1BActive UDP sessions   : 0\r\x1b[1BActive ICMP sessions  : 0\r\x1b[1B']

I was able to split the list with the following command

for i in l:
    i.splitlines()

['Total active sessions : 0', '\x1b[1BActive TCP sessions   : 0', '\x1b[1BActive UDP sessions   : 0', '\x1b[1BActive ICMP sessions  : 0', '\x1b[1B']

There is still appearing \x1b[1B in all elements in the table. I looked up the byte character and this appears to be a "Next line" character. Either way, how can I remove this from every element in the list?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

东京女 2025-02-12 03:25:32

尝试以下操作:

new_list = [e.replace('\x1b[1B','') for e in l]

Try this:

new_list = [e.replace('\x1b[1B','') for e in l]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文