愚蠢Python模块集合
项目描述
stupidity.py - 愚蠢Python代码的工具包
安装
pip install 愚蠢性
switch语句
你是否怀念Python中的经典switch语句?
from stupidity import switch
for case in switch('b'):
if case('a'):
print('this is not printed')
if case('b'):
print('this is printed')
if case('c'):
print('fallthrough is also supported')
break
if case('d'):
print('this is not printed either')
print('default value at bottom, but this is not reached')
认为if语句愚蠢?我们为你解决了这个问题!
from stupidity import switch
for case in switch('b'):
with case('a'):
print('this is not printed')
with case('b'):
print('this is printed')
with case('c'):
print('fallthrough is also supported')
break
with case('d'):
print('this is not printed either')
print('default value at bottom, but this is not reached')
认为for循环也愚蠢?我们也可以去除它们
from stupidity import switch
with switch('b') as case:
with case('a'):
print('this is not printed')
with case('b'):
print('this is printed')
with case('c'):
print('fallthrough is also supported')
BREAK # NOTE: We have to yell here
with case('d'):
print('this is not printed either')
print('default value at bottom, but this is not reached')
处理闭包变量
你是否对那些似乎就在你触手可及之外,但让你烦恼的闭包内部的变量感到烦恼?不必再担心了!
from stupidity import replace_closure_variables
def foo():
x = 42
def f():
return x
return f
f = foo()
f() # 42
replace_closure_variables(f, x=123)
f() # 123
花括号
众所周知,从__future__导入braces会失败得很惨
from __future__ import braces
# File "<stdin>", line 1
# SyntaxError: not a chance
幸运的是,我们提供了一个可行的实现
from stupidity import braces
x = 42;
if (x == 123): {
print('nope')
}
elif (x == 42): {
print('yep')
}
# prints 'yep'
项目详情
关闭
stupidity-0.0.1.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | fd40770018815e061b22a8ca994459638a01cf1d9edb1426853ca3e4462f07f8 |
|
MD5 | a728d9aabce4a611eca881368140c1ea |
|
BLAKE2b-256 | e20a390b447e4b6f5f21cd607229c6b564a912dae7105e6c32204e2561296fd2 |