跳转到主要内容

可能是一个小的Python包,仅包含raise_if函数

项目描述

[![构建
状态](https://travis-ci.org/rochacbruno/raise_if.png)](https://travis-ci.org/rochacbruno/raise_if)
[![覆盖率
状态](https://coveralls.io/repos/rochacbruno/raise_if/badge.png)](https://coveralls.io/r/rochacbruno/raise_if)
![工具](https://img.shields.io/badge/utility-0%25-lightgrey.svg)
![Emacs](https://img.shields.io/badge/built%20with-EMACs-blue.svg)

[![forthebadge](http://forthebadge.com/images/badges/built-with-love.svg)](http://forthebadge.com)
[![forthebadge](http://forthebadge.com/images/badges/gluten-free.svg)](http://forthebadge.com)
[![forthebadge](http://forthebadge.com/images/badges/built-by-developers.svg)](http://forthebadge.com)
# raise_if

Python可以像Ruby一样有raise条件。

```ruby
def i_must_have_truth(value)
raise TypeError, 'You must give me truth' if value == false
end
```

但只有一行选项能工作,这伤害了PEP8
```python
def i_must_have_truth(value)
if not value: raise TypeError('You must give me truth')
```

所以...

```python
$ pip install raise_if

import raise_if

def i_must_have_truth(value)
raise_if(not value, TypeError, 'You must give me truth')
```

传递异常类型和参数

```python
raise_if(not 1 == 2, TypeError, 'Fails', another_arg='foo')
```

或者

```python
raise_if(not 1 == 2, TypeError('Fails', another_arg='foo'))
```

为什么???

因为我懒,我不喜欢在if语句链中添加额外的换行符!

:)


项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分布

raise_if-0.1.4.tar.gz (2.1 kB 查看散列)

上传时间: 源码

由以下支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面