pydoc.render_doc()添加字符 - 如何避免? [英] pydoc.render_doc() adds characters - how to avoid that?

查看:400
本文介绍了pydoc.render_doc()添加字符 - 如何避免?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已经有一些问题可以解决这个问题,但没有人能够解决问题。

  import pydoc 
hlpTxt = pydoc.render_doc(帮助)

已经做了我想要的!打印到(右)控制台时看起来无瑕疵,但它包含以下额外字符:

  _\x08_H\x08He\\ \\ x08el\x08lp\x08pe\x08er\x08r 

在Maya中,它填充了 -symbols! help()也会使它无瑕疵。



删除 \x08 给我每个额外的一封信:

  __ HHeellppeerr 

这也不是很有用。
有人评论说,当它管道到子进程或文件时,它适用于他。我也没有这样做。是否有另一种方式

  hlpFile = open('c:/help.txt','w')
hlpFile.write(hlpTxt)
hlpFile.close()

?因为这让我有同样的问题。 Notepad ++实际上在地方显示BS符号。是的Backspace obwiously。



反正:一定有一个原因,这些符号被添加和删除它们以后可能会工作,但我不能想象没有办法

所以最后还有另一个 pydoc 方法我' m缺少? $ str.encode / decode 我还没看过吗?



btw: m不在寻找帮助.__ doc __

$ p

解决方案

您可以使用 pydoc.plain

  pydoc删除粗体序列。 plain(pydoc.render_doc(help))

 

 >>> help(pydoc.plain)
模块pydoc中的函数plain的帮助:

plain(text)
从文本中删除粗体格式。





在python 3 pydoc.render_doc 接受 renderer

  pydoc.render_doc(help,renderer = pydoc.plaintext)

&


There are already some questions touching this but no one seems to actually solve it.

import pydoc
hlpTxt = pydoc.render_doc(help)

already does what I want! looks flawless when printed to the (right) console but it has those extra characters included:

_\x08_H\x08He\x08el\x08lp\x08pe\x08er\x08r

In Maya for instance it looks like its filled up with -symbols! While help() renders it flawless as well.

Removing \x08 leaves me with an extra letter each:

__HHeellppeerr

which is also not very useful. Someone commented that it works for him when piped to a subprocess or into a file. I also failed to do that already. Is there another way than

hlpFile = open('c:/help.txt', 'w')
hlpFile.write(hlpTxt)
hlpFile.close()

? Because this leaves me with the same problem. Notepad++ actually shows BS symbols at the places. Yes for backspace obwiously.

Anyway: There must be a reason that these symbols are added and removing them afterwards might work but I can't imagine there isn't a way to have them not created in the first place!

So finally is there another pydoc method I'm missing? Or a str.encode/decode thing I have not yet seen?

btw: I'm not looking for help.__doc__!

解决方案

In python 2, you can remove the boldface sequences with pydoc.plain:

pydoc.plain(pydoc.render_doc(help))

 

>>> help(pydoc.plain)
Help on function plain in module pydoc:

plain(text)
    Remove boldface formatting from text.

 

In python 3 pydoc.render_doc accepts a renderer:

pydoc.render_doc(help, renderer=pydoc.plaintext)

 

这篇关于pydoc.render_doc()添加字符 - 如何避免?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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