提交 524dc30a 编写于 作者: 写代码的明哥's avatar 写代码的明哥

update

上级 615688f4
......@@ -84,9 +84,8 @@ ok
在讲多个条件组合时,先来了解一下 Python 中的逻辑运算符。
以下假设变量 a 为 10, b为 20:
| 运算符 | 逻辑表达式 | 描述 | 实例 |
| :----- | :--------- | :----------------------------------------------------------- | :---------------------- |
| 运算符 | 逻辑表达式 | 描述| 实例 |
| --- | --- | --- | --- |
| and | x and y | 布尔"与" - 如果 x 为 False,x and y 返回 False,否则它返回 y 的计算值。 | (a and b) 返回 20。 |
| or | x or y | 布尔"或" - 如果 x 是非 0,它返回 x 的值,否则它返回 y 的计算值。 | (a or b) 返回 10。 |
| not | not x | 布尔"非" - 如果 x 为 True,返回 False 。如果 x 为 False,它返回 True。 | not(a and b) 返回 False |
......@@ -111,4 +110,5 @@ if 条件A or 条件B:
# 要求不满足条件A
if not 条件A:
...
```
\ No newline at end of file
```
......@@ -33,7 +33,7 @@ RuntimeError: Something bad happened
```python
try:
print(1 / 0)
print(1/0)
except Exception as exc:
raise RuntimeError("Something bad happened") from exc
```
......
# 8.2 【基础】安装第三方包的种方法
# 8.2 【基础】安装第三方包的种方法
## 1. 使用 easy_install
......@@ -57,23 +57,65 @@ Success!
安装就可以使用 pipx 安装cli 工具了。
```shell
# 创建虚拟环境并安装包
$ pipx install pkg
```
更多 pipx 的使用方法,可参考本系列教程后面的文章,介绍得非常清楚:[12.4 pipx 安装程序的使用指南](https://demo.iswbm.com/en/latest/c12/c12_04.html)
## 4. 使用 yum install
## 4. 使用 setup.py
如果你有编写 setup.py 文件,可以使用如下命令直接安装
```python
# 使用源码直接安装
$ python setup.py install
```
## 5. 使用 yum
Python 包在使用 `setup.py` 构建的时候(具体内容可阅读后面的内容:[8.15 超详细讲解 setup.py 的编写](https://demo.iswbm.com/en/latest/c08/c08_15.html)),对于包的发布格式有多种选项,其中有一个选项是 `bdist_rpm`,以这个选项发布出来的包是 `rpm` 的包格式。
```shell
# 发布 rpm 包
$ python setup.py bdist_rpm
```
对于`rpm` 这种格式,你需要使用 `yum install xxx` 或者 `rpm install xxx` 来安装。
```shell
# 使用 yum 安装
$ yum install pkg
$ rpm install pkg
# 使用 rpm 安装
$ rpm -ivh pkg
```
## 6. 使用 pipenv
如果你在使用 pipenv 创建的虚拟环境中,可以使用下面这条命令把包安装到虚拟环境中
```shell
$ pipenv install pkg
```
## 7. 使用 poetry
如果你有使用 poetry 管理项目依赖,那么可以使用下面这条命令安装包
```shell
# 直接安装包
$ poetry add pkg
# 指定为开发依赖
$ poetry add pytest --dev
```
## 8. 使用 curl + 管道
有一些第三方工具包提供的安装方法,是直接使用 curl 配置管道来安装,比如上面提到的 poetry 就可以用这种方法安装。
```shell
$ curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python
```
......@@ -6,9 +6,8 @@
```python
# profile.py
name='wangbm'
age=27
gender='male'
name='小明'
age=18
__all__=['name']
```
......@@ -18,15 +17,11 @@ __all__=['name']
```python
>>> from profile import *
>>> print(name)
wangbm
小明
>>> print(age)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'age' is not defined
>>> print(gender)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'gender' is not defined
```
`__all__` 仅对于使用`from module import *` 这种情况适用。
......
......@@ -19,7 +19,7 @@
$ brew install pipenv
# windows
pip install [--user] pipenv
$ pip install [--user] pipenv
```
如果你的电脑是 windows 的。
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册