使用C样式大括号而不是缩进。
cstyle的Python项目详细描述
使用C样式大括号而不是缩进。这是一种编码,您也可以在sites.py中导入此模块,它将在导入时注册编码。
要使用此功能,请将magic编码注释添加到源文件:
# coding: cstyle
然后你可以导入它来运行它。或者,如果将编码添加到sites.py中,则可以使用idle查看解码的文件。 使用记事本++或您选择的编辑器。 不要用这个。不要用这个。不要用这个。这是可行的,但这不是个好主意。
目前只适用于“if elif else for while def with”语句。不要混合压痕和支撑。你可以这样做,但不建议这样做。 把这个模块当作一个玩具,或者如果你有任何特殊的用途来使用它。这个程序是开源的,lgpl,你可以免费编辑或使用它。
此模块的一个用途是减少源代码大小(压缩)。
您还可以解码cstyle文本:
import cstyle a = b'cstyle code' a.decode('cstyle')
要了解如何使用cstyle编写代码,请检查此处提供的示例。这不是alpha版本,这不是beta版本,这根本不是一个版本。这不是一个真正的程序,至少现在是这样。用于教育或其他用途。没有保证。可能存在解析错误,将在此处示例中提供的代码上对其进行测试。
这能做什么?
这将转换:
if(1 in {1,2,3}){ print(5) for(x in c){ print(c) } }
对此:
if(1 in {1,2,3}): print(5) for x in c: print(c)
它也适用于混乱的代码。查看如何处理这段长的单行代码:
import time;while(1){while(3){break}if(999>x){time.sleep(1);if(2){print("This is a BAD idea.");print("Or a good one?");print("For me, this is just for fun.");print("C-Style Coding");if(1){def xyz(a,b,c){"""this is a stupid function""";print("if(2){print(\\"hi\\")}");if(a>b){return c}elif(a>c){return b}else{return a}}}with(open("file") as f){pass}}}if(1 in {1,2,3}){print(5);for(x in c){print(c)}}}
前面的结果是:
import time while(1): while(3): break if(999>x): time.sleep(1) if(2): print("This is a BAD idea.") print("Or a good one?") print("For me, this is just for fun.") print("C-Style Coding") if(1): def xyz(a,b,c): """this is a stupid function""" print("if(2){print(\"hi\")}") if(a>b): return c elif(a>c): return b else: return a with open("file") as f: pass if(1 in {1,2,3}): print(5) for x in c: print(c)
项目信息
github项目页面:https://github.com/pooya-eghbali/cstyle 请发邮件至:persian.writer[网址]gmail.com