Python Source Formatter/Pretty Printer [closed]

一个人想着一个人 提交于 2019-11-29 09:20:59

http://pypi.python.org/pypi/PythonTidy is an excellent, simple script.

I've found that PyLint and other code analysis tools all choke on pyrex, twisted and other modules.

If you want formatting, just use PythonTidy.

Depends of what you mean by "format/pretty-print Python source code".

There's Pygments that do syntax highlighting and you can try it online at Lodgeit (it's a pastebin).

There's also the pprint module in the standard library that pretty-print python data sctructures (dict, list, etc.).

If you need help to format you own python code you can use some text editors that have tools to do that, like PyDev/Eclipse.

http://www.polystyle.com/features/python-formatter.jsp

Polyglot, commercial (cheap) source code beautifier/obfuscator for several languages, including Python. Also: website has not been updated in 5 years, runs on Windows, so it may not be what you need.

A better alternative would be autopep8:

autopep8 automatically formats Python code to conform to the PEP 8 style guide. It uses the pep8 utility to determine what parts of the code needs to be formatted. autopep8 is capable of fixing most of the formatting issues that can be reported by pep8.

Since I found the source of PythonTidy to be somewhat messy and hard to extend, I have recently started a new and fully open source project for Python formatting. It uses the tokenize library in Python to make sure we tokenize and untokenize correctly and is build to be very extendable.

Please take a look and let me know if you have any issues and/or have feature requests: https://github.com/WoLpH/python-formatter

The programs ...

... can all pretty print Python source code with color. (They can also pretty print other languages.)

They have Ubuntu package names pygments, source-highlight, enscript, respectively.

I found python beautifier from this link http://arachnoid.com/python/pybeautify_program.html

It's quite helpful for me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!