Python源代码美化 [英] Python Source Code Beautifier

查看:101
本文介绍了Python源代码美化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我没有找到任何合理的pyhton源代码美化

程序(最好是gui)。


有人会问为什么?把它编程一下就好了。


(顺便说一下:如果我有更多的业余时间,那将是一个不错的项目。)


Ich有一些外国来源,在某种程度上编程

我不喜欢,所以我想有一个工具,它会自动处理以下选项:

使用空格,大小:4

转换结构如:if(ab):如果ab:

填充空格,但不填写运算符之间的函数:


a + = 1 = a + = 1

p(t + 1)= p(t + 1)


兑换:


self.scriptcount = self.scriptcount + 1 = self.scriptcount + = 1

来自是的
到==和不是到!= (好的,找到替换可以做到这一点

也很容易),但是在一个更舒服的程序中。


打破长线(合理的方式) )


来自:
if len(string)0:= if string:



if if len(string)< 1 orr if string =="" =如果不是字符串


检测混合行结尾

检测与空格混合的标签

修剪尾随空格。
< br $> b $ b .....

.....

有这样的工具吗?


之后自动运行Pylint或Pycheck

将是加冕礼。 :)

解决方案

Franz Steinhaeusler:


您好,我没有找到任何合理的pyhton源代码美化

程序(首选gui)。

...

转换:

...
来自是的
到==和不是到!= (好的,找到替换也可以轻松地做到这一点

),但是在一个更舒服的程序中。



这是一种不安全的转换。我不认为合理的程序可以静态地确定是。相当于

" =="除了琐碎的代码之外。


Neil


Franz Steinhaeusler于2007年2月27日星期二09:45:42写了这篇文章+0100。我的

回复如下。


您好,我没有找到任何合理的pyhton源代码美化

program (首选gui)。



-snip-


是否有这样的工具?



为什么,是的!是的,有:


o http:/ /lacusveris.com/PythonTidy/PythonTidy.python


它没有图形用户界面,也没有

你想要的一切,这是不合理的(这是一个不合理的

大小。),但这是一个开始。


供将来参考,请查看:

o http: //cheeseshop.python.org/pypi


....在重新格式化下。


-

... Chuck Rhode,Sheboygan,WI,USA

...天气: http://LacusVeris.com/WX

... 26?°a ??风WNW 5英里每小时?天空阴云密布。 Mist。


Il Tue,2007年2月27日09:45:42 +0100,Franz Steinhaeusler ha scritto:


您好,我没有找到任何合理的pyhton源代码美化

程序(首选gui)。



好​​吧,你提出的大部分内容应该是这样编写的,不是写的,而是b / b
然后美化!


使用空格,大小:4



你的编辑应该支持这个。


转换结构如:if(ab):如果ab:



嗯......这是事实,而不仅仅是风格。有时候括号会帮助你读取b
;如果a,b不仅仅是普通的名字,而是有点复杂的

指令,括号应该保留。


填写空格,但不填写函数运营商之间:


a + = 1 = a + = 1

p(t + 1)= p(t + 1)


代码应该这样写。


self.scriptcount = self.scriptcount + 1 = self.scriptcount + = 1



+ =运算符是语法糖只是为了节省时间...如果一个人不使用

它我不认为这是美的问题。


>
来自is的
到==和不是到!= (好的,找到替换也可以轻松地做到这一点

),但是在一个更舒服的程序中。



什么?不,我认为你错过了''是''和''==''之间的区别。你

可以用另一种方式来表示None,True,False,例如如果有一个'= a ==

无''它可以安全地转换为''a is None'',但是再次:这应该是

要完成在编写代码时。


打破长行(以合理的方式)



well ...这有时候很有用,但是......理由通常是人类应该使用的东西,而不应该外包给

计算机程序。


来自:
if len(string)0:= if string:



if if len(string)< 1 orr if string =="" =如果不是字符串



这是不可能的! Python是动态类型的! ''美化''

怎么能理解''字符串''这个名字的含义?它可能是任何对象!


检测混合行结尾

检测与空格混合的标签

修剪尾随空格。



这些是编辑任务。


获得一个好的编辑或IDE。你还没告诉我们你在做什么操作系统。如果你在Windows上获得
,UltraEdit可以完成你想要的大部分事情。并且不要在软件上依赖

来纠正人类行为^ _ ^。


-

Alan Franzoni< ; al *************** @ gmail.com>

-

Togli .xyz dalla mia电子邮件每contattarmi。

从我的地址删除.xyz以便与我联系。

-

GPG密钥指纹(密钥ID = FE068F3E):

5C77 9DC3 BD5B 3A28 E7BC 921A 0255 42AA FE06 8F3E


Hello, I did not find any reasonable pyhton source code beautifier
program (preferable gui).

Some would ask why? Program it immediatly good.

(BTW: Would be a nice project, if I would have more spare time).

Ich have some foreign source, which are programed in a way
I don''t like, so I would like to have a tool, which automatically
processes following options:
Use Spaces, size: 4
convert structs like: if (a b): to if a b:
fill in spaces, but not in functions between operators:

a+=1 =a += 1
p(t + 1) =p(t+1)

convert:

self.scriptcount = self.scriptcount + 1 =self.scriptcount += 1

from "is" to "==" and "is not" to "!=" (ok a find replace could do that
easily also), but in a program that would be more comfortable.

break long lines (in a reasonable way)

make from:
if len(string) 0: =if string:
and
if if len(string) < 1 orr if string == "" =if not string

detect mixed line ending
detect tabs mixed with space
trim trailing whitespaces.

.....
.....
Is there such a tool around?

Running Pylint or Pycheck automatically afterwards
would be the coronation. :)

解决方案

Franz Steinhaeusler:

Hello, I did not find any reasonable pyhton source code beautifier
program (preferable gui).
...
convert:
...
from "is" to "==" and "is not" to "!=" (ok a find replace could do that
easily also), but in a program that would be more comfortable.

That''s an unsafe conversion. I don''t think it is possible for a
reasonable program to determine statically that "is" is equivalent to
"==" except for trivial pieces of code.

Neil


Franz Steinhaeusler wrote this on Tue, 27 Feb 2007 09:45:42 +0100. My
reply is below.

Hello, I did not find any reasonable pyhton source code beautifier
program (preferable gui).

-snip-

Is there such a tool around?

Why, yes! Yes, there is:

o http://lacusveris.com/PythonTidy/PythonTidy.python

It doesn''t have a graphical user interface, and it doesn''t do
everything you want, and it isn''t reasonable (It''s of an unreasonable
size.), but it is a beginning.

For future reference, look in:

o http://cheeseshop.python.org/pypi

.... under "reformat."

--
... Chuck Rhode, Sheboygan, WI, USA
... Weather: http://LacusVeris.com/WX
... 26?° a?? Wind WNW 5 mph a?? Sky overcast. Mist.


Il Tue, 27 Feb 2007 09:45:42 +0100, Franz Steinhaeusler ha scritto:

Hello, I did not find any reasonable pyhton source code beautifier
program (preferable gui).

Well, most of the things you ask should be written as such, not written and
then beautified!

Use Spaces, size: 4

Your editor should support this.

convert structs like: if (a b): to if a b:

Well... that''s a matter of fact, not just style. Sometimes parentheses help
the reading; if a,b are not just plain names but somewhat complex
instructions, parentheses should stay.

fill in spaces, but not in functions between operators:

a+=1 =a += 1
p(t + 1) =p(t+1)

Code should be written this way.

self.scriptcount = self.scriptcount + 1 =self.scriptcount += 1

the += operator is syntactic sugar just to save time... if one doesn''t use
it I don''t think it''s a matter of beauty.

>
from "is" to "==" and "is not" to "!=" (ok a find replace could do that
easily also), but in a program that would be more comfortable.

what? No, I think you''re missing the difference between ''is'' and ''==''. You
could say it the other way for None, True, False, e.g. if there''s a ''a ==
None'' it could be safely converted to ''a is None'', but again: this should
be done while writing the code.

break long lines (in a reasonable way)

well... this could be useful sometimes, but again... ''reason'' is usually
something human beings should employ, and shouldn''t be ''outsourced'' to
computer programs.

make from:
if len(string) 0: =if string:
and
if if len(string) < 1 orr if string == "" =if not string

That''s impossibile! Python is dynamically typed! How could the ''beautifier''
understand what the ''string'' name is bound to? It could be whatever object!

detect mixed line ending
detect tabs mixed with space
trim trailing whitespaces.

Those are editor tasks.

Get a good Editor or IDE. You haven''t told us what OS are you on. If you''re
on Windows, UltraEdit can do most of the things you''d like. And don''t rely
on a software to correct human behaviours ^_^.

--
Alan Franzoni <al***************@gmail.com>
-
Togli .xyz dalla mia email per contattarmi.
Remove .xyz from my address in order to contact me.
-
GPG Key Fingerprint (Key ID = FE068F3E):
5C77 9DC3 BD5B 3A28 E7BC 921A 0255 42AA FE06 8F3E


这篇关于Python源代码美化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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