mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-03-24 02:20:09 +08:00
Merge remote-tracking branch 'LCTT/master'
This commit is contained in:
commit
3aa05ae5a9
published
20180327 Loop better- A deeper look at iteration in Python.md20180509 3 Methods To Install Latest Python3 Package On CentOS 6 System.md
sources
talk
tech
translated
@ -1,9 +1,11 @@
|
||||
Loop better:更深入的理解Python 中的迭代
|
||||
更深入的理解 Python 中的迭代
|
||||
====
|
||||
|
||||
> 深入探讨 Python 的 `for` 循环来看看它们在底层如何工作,以及为什么它们会按照它们的方式工作。
|
||||
|
||||

|
||||
|
||||
Python 的 `for` 循环不会像其他语言中的 `for` 循环那样工作。在这篇文章中,我们将深入探讨 Python 的 `for` 循环来看看它们如何在底层工作,以及为什么它们会按照它们的方式工作。
|
||||
Python 的 `for` 循环不会像其他语言中的 `for` 循环那样工作。在这篇文章中,我们将深入探讨 Python 的 `for` 循环来看看它们在底层如何工作,以及为什么它们会按照它们的方式工作。
|
||||
|
||||
### 循环的问题
|
||||
|
||||
@ -12,27 +14,24 @@ Python 的 `for` 循环不会像其他语言中的 `for` 循环那样工作。
|
||||
#### 问题 1:循环两次
|
||||
|
||||
假设我们有一个数字列表和一个生成器,生成器会返回这些数字的平方:
|
||||
|
||||
```
|
||||
>>> numbers = [1, 2, 3, 5, 7]
|
||||
|
||||
>>> squares = (n**2 for n in numbers)
|
||||
|
||||
```
|
||||
|
||||
我们可以将生成器对象传递给 `tuple` 构造器,从而使其变为一个元组:
|
||||
|
||||
```
|
||||
>>> tuple(squares)
|
||||
|
||||
(1, 4, 9, 25, 49)
|
||||
|
||||
```
|
||||
|
||||
如果我们使用相同的生成器对象并将其传给 `sum` 函数,我们可能会期望得到这些数的和,即 88。
|
||||
如果我们使用相同的生成器对象并将其传给 `sum` 函数,我们可能会期望得到这些数的和,即 `88`。
|
||||
|
||||
```
|
||||
>>> sum(squares)
|
||||
|
||||
0
|
||||
|
||||
```
|
||||
|
||||
但是我们得到了 `0`。
|
||||
@ -40,6 +39,7 @@ Python 的 `for` 循环不会像其他语言中的 `for` 循环那样工作。
|
||||
#### 问题 2:包含的检查
|
||||
|
||||
让我们使用相同的数字列表和相同的生成器对象:
|
||||
|
||||
```
|
||||
>>> numbers = [1, 2, 3, 5, 7]
|
||||
|
||||
@ -48,15 +48,12 @@ Python 的 `for` 循环不会像其他语言中的 `for` 循环那样工作。
|
||||
```
|
||||
|
||||
如果我们询问 `9` 是否在 `squares` 生成器中,Python 将会告诉我们 9 在 `squares` 中。但是如果我们再次询问相同的问题,Python 会告诉我们 9 不在 `squares` 中。
|
||||
|
||||
```
|
||||
>>> 9 in squares
|
||||
|
||||
True
|
||||
|
||||
>>> 9 in squares
|
||||
|
||||
False
|
||||
|
||||
```
|
||||
|
||||
我们询问相同的问题两次,Python 给了两个不同的答案。
|
||||
@ -64,57 +61,51 @@ False
|
||||
#### 问题 3 :拆包
|
||||
|
||||
这个字典有两个键值对:
|
||||
|
||||
```
|
||||
>>> counts = {'apples': 2, 'oranges': 1}
|
||||
|
||||
```
|
||||
|
||||
让我们使用多个变量来对这个字典进行拆包:
|
||||
|
||||
```
|
||||
>>> x, y = counts
|
||||
|
||||
```
|
||||
|
||||
你可能会期望当我们对这个字典进行拆包时,我们会得到键值对或者得到一个错误。
|
||||
|
||||
但是解包字典不会引发错误,也不会返回键值对。当你解包一个字典时,你会得到键:
|
||||
|
||||
```
|
||||
>>> x
|
||||
|
||||
'apples'
|
||||
|
||||
```
|
||||
|
||||
### 回顾:Python 的 __for__ 循环
|
||||
### 回顾:Python 的 for 循环
|
||||
|
||||
在我们了解一些关于这些 Python 片段的逻辑之后,我们将回到这些问题。
|
||||
|
||||
Python 没有传统的 `for` 循环。为了解释我的意思,让我们看一看另一种编程语言的 `for` 循环。
|
||||
|
||||
这是一种传统 C 风格的 `for` 循环,用 JavaScript 编写:
|
||||
|
||||
```
|
||||
let numbers = [1, 2, 3, 5, 7];
|
||||
|
||||
for (let i = 0; i < numbers.length; i += 1) {
|
||||
|
||||
print(numbers[i])
|
||||
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
JavaScript, C, C++, Java, PHP, 和一大堆其他编程语言都有这种风格的 `for` 循环,但是 Python **确实没**。
|
||||
JavaScript、 C、 C++、 Java、 PHP 和一大堆其他编程语言都有这种风格的 `for` 循环,但是 Python **确实没有**。
|
||||
|
||||
Python **确实没** 有传统 C 风格的 `for` 循环。在 Python 中确实有一些我们称之为 `for` 循环的东西,但是它的工作方式类似于 [foreach loop][1]。
|
||||
Python **确实没有** 传统 C 风格的 `for` 循环。在 Python 中确实有一些我们称之为 `for` 循环的东西,但是它的工作方式类似于 [foreach 循环][1]。
|
||||
|
||||
这是 Python 的 `for` 循环的风格:
|
||||
|
||||
```
|
||||
numbers = [1, 2, 3, 5, 7]
|
||||
|
||||
for n in numbers:
|
||||
|
||||
print(n)
|
||||
|
||||
```
|
||||
|
||||
与传统 C 风格的 `for` 循环不同,Python 的 `for` 循环没有索引变量,没有索引变量初始化,边界检查,或者索引递增。Python 的 `for` 循环完成了对我们的 `numbers` 列表进行遍历的所有工作。
|
||||
@ -126,98 +117,75 @@ for n in numbers:
|
||||
既然我们已经解决了 Python 世界中无索引的 `for` 循环,那么让我们在此之外来看一些定义。
|
||||
|
||||
**可迭代**是任何你可以用 Python 中的 `for` 循环遍历的东西。可迭代意味着可以遍历,任何可以遍历的东西都是可迭代的。
|
||||
|
||||
```
|
||||
for item in some_iterable:
|
||||
|
||||
print(item)
|
||||
|
||||
```
|
||||
|
||||
序列是一种非常常见的可迭代类型,列表,元组和字符串都是序列。
|
||||
|
||||
```
|
||||
>>> numbers = [1, 2, 3, 5, 7]
|
||||
|
||||
>>> coordinates = (4, 5, 7)
|
||||
|
||||
>>> words = "hello there"
|
||||
|
||||
```
|
||||
|
||||
序列是可迭代的,它有一些特定的特征集。它们可以从 `0` 开始索引,以小于序列的长度结束,它们有一个长度并且它们可以被切分。列表,元组,字符串和其他所有序列都是这样工作的。
|
||||
|
||||
```
|
||||
>>> numbers[0]
|
||||
|
||||
1
|
||||
|
||||
>>> coordinates[2]
|
||||
|
||||
7
|
||||
|
||||
>>> words[4]
|
||||
|
||||
'o'
|
||||
|
||||
```
|
||||
|
||||
Python 中很多东西都是可迭代的,但不是所有可迭代的东西都是序列。集合,字典,文件和生成器都是可迭代的,但是它们都不是序列。
|
||||
Python 中很多东西都是可迭代的,但不是所有可迭代的东西都是序列。集合、字典、文件和生成器都是可迭代的,但是它们都不是序列。
|
||||
|
||||
```
|
||||
>>> my_set = {1, 2, 3}
|
||||
|
||||
>>> my_dict = {'k1': 'v1', 'k2': 'v2'}
|
||||
|
||||
>>> my_file = open('some_file.txt')
|
||||
|
||||
>>> squares = (n**2 for n in my_set)
|
||||
|
||||
```
|
||||
|
||||
因此,任何可以用 `for` 循环遍历的东西都是可迭代的,序列只是一种可迭代的类型,但是 Python 也有许多其他种类的迭代器。
|
||||
|
||||
### Python 的 __for__ 循环不使用索引
|
||||
### Python 的 for 循环不使用索引
|
||||
|
||||
你可能认为,Python 的 `for` 循环在底层使用了索引进行循环。在这里我们使用 `while` 循环和索引手动遍历:
|
||||
|
||||
你可能认为,在 hood 下的 `for` 循环中使用索引进行循环。在这里我们使用 `while` 循环和索引手动遍历:
|
||||
```
|
||||
numbers = [1, 2, 3, 5, 7]
|
||||
|
||||
i = 0
|
||||
|
||||
while i < len(numbers):
|
||||
|
||||
print(numbers[i])
|
||||
|
||||
i += 1
|
||||
|
||||
```
|
||||
|
||||
这适用于列表,但它不会对所有东西都起作用。这种循环方式**只适用于序列**。
|
||||
|
||||
如果我们尝试用索引去手动遍历一个集合,我们会得到一个错误:
|
||||
|
||||
```
|
||||
>>> fruits = {'lemon', 'apple', 'orange', 'watermelon'}
|
||||
|
||||
>>> i = 0
|
||||
|
||||
>>> while i < len(fruits):
|
||||
|
||||
... print(fruits[i])
|
||||
|
||||
... i += 1
|
||||
|
||||
...
|
||||
|
||||
Traceback (most recent call last):
|
||||
|
||||
File "<stdin>", line 2, in <module>
|
||||
|
||||
TypeError: 'set' object does not support indexing
|
||||
|
||||
```
|
||||
|
||||
集合不是序列,所以它们不支持索引。
|
||||
|
||||
我们不能使用索引手动对 Python 中的每一个迭代对象进行遍历。对于那些不是序列的迭代器来说,这是行不通的。
|
||||
|
||||
### 迭代器驱动 __for__ 循环
|
||||
### 迭代器驱动 for 循环
|
||||
|
||||
因此,我们已经看到,Python 的 `for` 循环在底层不使用索引。相反,Python 的 `for` 循环使用**迭代器**。
|
||||
|
||||
@ -226,148 +194,116 @@ TypeError: 'set' object does not support indexing
|
||||
让我们来看看它是如何工作的。
|
||||
|
||||
这里有三个可迭代对象:一个集合,一个元组和一个字符串。
|
||||
|
||||
```
|
||||
>>> numbers = {1, 2, 3, 5, 7}
|
||||
|
||||
>>> coordinates = (4, 5, 7)
|
||||
|
||||
>>> words = "hello there"
|
||||
|
||||
```
|
||||
|
||||
我们可以使用 Python 的内置 `iter` 函数来访问这些迭代器,将一个迭代器传递给 `iter` 函数总会给我们返回一个迭代器,无论我们正在使用哪种类型的迭代器。
|
||||
|
||||
```
|
||||
>>> iter(numbers)
|
||||
|
||||
<set_iterator object at 0x7f2b9271c860>
|
||||
|
||||
>>> iter(coordinates)
|
||||
|
||||
<tuple_iterator object at 0x7f2b9271ce80>
|
||||
|
||||
>>> iter(words)
|
||||
|
||||
<str_iterator object at 0x7f2b9271c860>
|
||||
|
||||
```
|
||||
|
||||
一旦我们有了迭代器,我们可以做的事情就是通过将它传递给内置的 `next` 函数来获取它的下一项。
|
||||
|
||||
```
|
||||
>>> numbers = [1, 2, 3]
|
||||
|
||||
>>> my_iterator = iter(numbers)
|
||||
|
||||
>>> next(my_iterator)
|
||||
|
||||
1
|
||||
|
||||
>>> next(my_iterator)
|
||||
|
||||
2
|
||||
|
||||
```
|
||||
|
||||
迭代器是有状态的,这意味着一旦你从它们中消耗了一项,它就消失了。
|
||||
|
||||
如果你从迭代器中请求 `next` 项,但是其中没有更多的项了,你将得到一个 `StopIteration` 异常:
|
||||
|
||||
```
|
||||
>>> next(my_iterator)
|
||||
|
||||
3
|
||||
|
||||
>>> next(my_iterator)
|
||||
|
||||
Traceback (most recent call last):
|
||||
|
||||
File "<stdin>", line 1, in <module>
|
||||
|
||||
StopIteration
|
||||
|
||||
```
|
||||
|
||||
所以你可以从每个迭代中获得一个迭代器,迭代器唯一能做的事情就是用 `next` 函数请求它们的下一项。如果你将它们传递给 `next`,但它们没有下一项了,那么就会引发 `StopIteration` 异常。
|
||||
|
||||
你可以将迭代器想象成 Pez 分配器(译注:Pez 是一个结合玩具的独特复合式糖果),不能重新分配。你可以把 Pez 拿出去,但是一旦 Pez 被移走,它就不能被放回去,一旦分配器空了,它就没用了。
|
||||
你可以将迭代器想象成 Pez 分配器(LCTT 译注:Pez 是一个结合玩具的独特复合式糖果),不能重新分配。你可以把 Pez 拿出去,但是一旦 Pez 被移走,它就不能被放回去,一旦分配器空了,它就没用了。
|
||||
|
||||
### 没有 __for__ 的循环
|
||||
### 没有 for 的循环
|
||||
|
||||
既然我们已经了解了迭代器和 `iter` 以及 `next` 函数,我们将尝试在不使用 `for` 循环的情况下手动遍历迭代器。
|
||||
|
||||
我们将通过尝试将这个 `for` 循环变为 `while` 循环:
|
||||
|
||||
```
|
||||
def funky_for_loop(iterable, action_to_do):
|
||||
|
||||
for item in iterable:
|
||||
|
||||
action_to_do(item)
|
||||
|
||||
```
|
||||
|
||||
为了做到这点,我们需要:
|
||||
|
||||
1. 从给定的可迭代对象中获得迭代器
|
||||
2. 反复从迭代器中获得下一项
|
||||
3. 如果我们成功获得下一项,就执行 `for` 循环的主体
|
||||
4. 如果我们在获得下一项时得到了一个 `StopIteration` 异常,那么就停止循环
|
||||
|
||||
|
||||
```
|
||||
def funky_for_loop(iterable, action_to_do):
|
||||
|
||||
iterator = iter(iterable)
|
||||
|
||||
done_looping = False
|
||||
|
||||
while not done_looping:
|
||||
|
||||
try:
|
||||
|
||||
item = next(iterator)
|
||||
|
||||
except StopIteration:
|
||||
|
||||
done_looping = True
|
||||
|
||||
else:
|
||||
|
||||
action_to_do(item)
|
||||
|
||||
```
|
||||
|
||||
我们只是通过使用 `while` 循环和迭代器重新定义了 `for` 循环。
|
||||
|
||||
上面的代码基本上定义了 Python 在底层循环的工作方式。如果你理解内置的 `iter` 和 `next` 函数的遍历循环的工作方式,那么你就会理解 Python 的 `for` 循环是如何工作的。
|
||||
|
||||
事实上,你不仅仅会理解 `for` 循环在 Python 中式如何工作的,所有形式的遍历一个可迭代对象都是这样工作的。
|
||||
事实上,你不仅仅会理解 `for` 循环在 Python 中是如何工作的,所有形式的遍历一个可迭代对象都是这样工作的。
|
||||
|
||||
**迭代器协议** 是一种很好的方式,它表示 "在 Python 中遍历迭代器是如何工作的"。它本质上是对 `iter` 和 `next` 函数在 Python 中是如何工作的定义。Python 中所有形式的迭代都是由迭代器协议驱动的。
|
||||
<ruby>迭代器协议<rt>iterator protocol</rt></ruby> 是一种很好表示 “在 Python 中遍历迭代器是如何工作的”的方式。它本质上是对 `iter` 和 `next` 函数在 Python 中是如何工作的定义。Python 中所有形式的迭代都是由迭代器协议驱动的。
|
||||
|
||||
迭代器协议被 `for` 循环使用(正如我们已经看到的那样):
|
||||
|
||||
```
|
||||
for n in numbers:
|
||||
|
||||
print(n)
|
||||
|
||||
```
|
||||
|
||||
多重赋值也使用迭代器协议:
|
||||
|
||||
```
|
||||
x, y, z = coordinates
|
||||
|
||||
```
|
||||
|
||||
星型表达式也是用迭代器协议:
|
||||
|
||||
```
|
||||
a, b, *rest = numbers
|
||||
|
||||
print(*numbers)
|
||||
|
||||
```
|
||||
|
||||
许多内置函数依赖于迭代器协议:
|
||||
|
||||
```
|
||||
unique_numbers = set(numbers)
|
||||
|
||||
```
|
||||
|
||||
在 Python 中任何与迭代器一起工作的东西都可能以某种方式使用迭代器协议。每当你在 Python 中遍历一个可迭代对象时,你将依赖于迭代器协议。
|
||||
@ -379,41 +315,31 @@ unique_numbers = set(numbers)
|
||||
我有消息告诉你:在 Python 中直接使用迭代器是很常见的。
|
||||
|
||||
这里的 `squares` 对象是一个生成器:
|
||||
|
||||
```
|
||||
>>> numbers = [1, 2, 3]
|
||||
|
||||
>>> squares = (n**2 for n in numbers)
|
||||
|
||||
```
|
||||
|
||||
生成器是迭代器,这意味着你可以在生成器上调用 `next` 来获得它的下一项:
|
||||
|
||||
```
|
||||
>>> next(squares)
|
||||
|
||||
1
|
||||
|
||||
>>> next(squares)
|
||||
|
||||
4
|
||||
|
||||
```
|
||||
|
||||
但是如果你以前用过生成器,你可能也知道可以循环遍历生成器:
|
||||
|
||||
```
|
||||
>>> squares = (n**2 for n in numbers)
|
||||
|
||||
>>> for n in squares:
|
||||
|
||||
... print(n)
|
||||
|
||||
...
|
||||
|
||||
1
|
||||
|
||||
4
|
||||
|
||||
9
|
||||
|
||||
```
|
||||
|
||||
如果你可以在 Python 中循环遍历某些东西,那么它就是**可迭代的**。
|
||||
@ -424,90 +350,84 @@ unique_numbers = set(numbers)
|
||||
|
||||
所以在我之前解释迭代器如何工作时,我跳过了它们的某些重要的细节。
|
||||
|
||||
**生成器是可迭代的。**
|
||||
#### 生成器是可迭代的
|
||||
|
||||
我再说一遍:Python 中的每一个迭代器都是可迭代的,意味着你可以循环遍历迭代器。
|
||||
|
||||
因为迭代器也是可迭代的,所以你可以使用内置 `next` 函数从可迭代对象中获得迭代器:
|
||||
|
||||
```
|
||||
>>> numbers = [1, 2, 3]
|
||||
|
||||
>>> iterator1 = iter(numbers)
|
||||
|
||||
>>> iterator2 = iter(iterator1)
|
||||
|
||||
```
|
||||
|
||||
请记住,当我们在可迭代对象上调用 `iter` 时,它会给我们返回一个迭代器。
|
||||
|
||||
当我们在迭代器上调用 `iter` 时,它会给我们返回它自己:
|
||||
|
||||
```
|
||||
>>> iterator1 is iterator2
|
||||
|
||||
True
|
||||
|
||||
```
|
||||
|
||||
迭代器是可迭代的,所有的迭代器都是它们自己的迭代器。
|
||||
|
||||
```
|
||||
def is_iterator(iterable):
|
||||
|
||||
return iter(iterable) is iterable
|
||||
|
||||
```
|
||||
|
||||
迷惑了吗?
|
||||
|
||||
让我们回顾一些这些措辞。
|
||||
|
||||
* 一个**可迭代对象**是你可以迭代的东西
|
||||
* 一个**可迭代对象**是一种可以迭代遍历迭代的代理
|
||||
(这句话不是很理解)
|
||||
* 一个**迭代对象器**是一种实际上遍历可迭代对象的代理
|
||||
|
||||
此外,在 Python 中迭代器也是可迭代的,它们充当它们自己的迭代器。
|
||||
|
||||
所以迭代器是可迭代的,但是它们没有一些可迭代对象拥有的各种特性。
|
||||
|
||||
迭代器没有长度,它们不能被索引:
|
||||
|
||||
```
|
||||
>>> numbers = [1, 2, 3, 5, 7]
|
||||
|
||||
>>> iterator = iter(numbers)
|
||||
|
||||
>>> len(iterator)
|
||||
|
||||
TypeError: object of type 'list_iterator' has no len()
|
||||
|
||||
>>> iterator[0]
|
||||
|
||||
TypeError: 'list_iterator' object is not subscriptable
|
||||
|
||||
```
|
||||
|
||||
从我们作为 Python 程序员的角度来看,你可以使用迭代器来做的唯一有用的事情是将其传递给内置的 `next` 函数,或者对其进行循环遍历:
|
||||
|
||||
```
|
||||
>>> next(iterator)
|
||||
|
||||
1
|
||||
|
||||
>>> list(iterator)
|
||||
|
||||
[2, 3, 5, 7]
|
||||
|
||||
```
|
||||
|
||||
如果我们第二次循环遍历迭代器,我们将一无所获:
|
||||
|
||||
```
|
||||
>>> list(iterator)
|
||||
|
||||
[]
|
||||
|
||||
```
|
||||
|
||||
你可以把迭代器看作是**惰性迭代器**,它们是**一次性使用**,这意味着它们只能循环遍历一次。
|
||||
|
||||
正如你在下面的真值表中所看到的,可迭代对象并不总是迭代器,但是迭代器总是可迭代的:
|
||||
|
||||
可迭代对象?迭代器?可迭代的? ✔️ ❓ 迭代器 ✔️ ✔️ 生成器 ✔️ ✔️ 列表 ✔️ ❌
|
||||
|
||||
对象 | 可迭代? | 迭代器?
|
||||
---------|---------|------
|
||||
可迭代对象 | V | ?
|
||||
迭代器 | V | V
|
||||
生成器 | V | V
|
||||
列表 | V | X
|
||||
|
||||
|
||||
### 全部的迭代器协议
|
||||
|
||||
@ -535,45 +455,33 @@ TypeError: 'list_iterator' object is not subscriptable
|
||||
### 迭代器无处不在
|
||||
|
||||
你已经在 Python 中看到过许多迭代器,我也提到过生成器是迭代器。Python 的许多内置类型也是迭代器。例如,Python 的 `enumerate` 和 `reversed` 对象就是迭代器。
|
||||
|
||||
```
|
||||
>>> letters = ['a', 'b', 'c']
|
||||
|
||||
>>> e = enumerate(letters)
|
||||
|
||||
>>> e
|
||||
|
||||
<enumerate object at 0x7f112b0e6510>
|
||||
|
||||
>>> next(e)
|
||||
|
||||
(0, 'a')
|
||||
|
||||
```
|
||||
|
||||
在 Python 3 中,`zip`, `map` 和 `filter` 也是迭代器。
|
||||
|
||||
```
|
||||
>>> numbers = [1, 2, 3, 5, 7]
|
||||
|
||||
>>> letters = ['a', 'b', 'c']
|
||||
|
||||
>>> z = zip(numbers, letters)
|
||||
|
||||
>>> z
|
||||
|
||||
<zip object at 0x7f112cc6ce48>
|
||||
|
||||
>>> next(z)
|
||||
|
||||
(1, 'a')
|
||||
|
||||
```
|
||||
|
||||
Python 中的 文件对象也是迭代器。
|
||||
Python 中的文件对象也是迭代器。
|
||||
|
||||
```
|
||||
>>> next(open('hello.txt'))
|
||||
|
||||
'hello world\n'
|
||||
|
||||
```
|
||||
|
||||
在 Python 标准库和第三方库中内置了大量的迭代器。这些迭代器首先惰性迭代器一样,延迟工作直到你请求它们下一项。
|
||||
@ -584,51 +492,37 @@ Python 中的 文件对象也是迭代器。
|
||||
知道你已经在使用迭代器是很有用的,但是我希望你也知道,你可以创建自己的迭代器和你自己的惰性迭代器。
|
||||
|
||||
下面这个类构造了一个迭代器接受一个可迭代的数字,并在循环结束时提供每个数字的平方。
|
||||
|
||||
```
|
||||
class square_all:
|
||||
|
||||
def __init__(self, numbers):
|
||||
|
||||
self.numbers = iter(numbers)
|
||||
|
||||
def __next__(self):
|
||||
|
||||
return next(self.numbers) * 2
|
||||
|
||||
def __iter__(self):
|
||||
|
||||
return self
|
||||
|
||||
```
|
||||
|
||||
但是在我们开始对该类的实例进行循环遍历之前,没有任何工作要做。
|
||||
|
||||
这里,我们有一个无限长的可迭代对象 `count`,你可以看到 `square_all` 接受 `count` 而不用完全循环遍历这个无限长的迭代:
|
||||
|
||||
```
|
||||
>>> from itertools import count
|
||||
|
||||
>>> numbers = count(5)
|
||||
|
||||
>>> squares = square_all(numbers)
|
||||
|
||||
>>> next(squares)
|
||||
|
||||
25
|
||||
|
||||
>>> next(squares)
|
||||
|
||||
36
|
||||
|
||||
```
|
||||
|
||||
这个迭代器类是有效的,但我们通常不会这样做。通常,当我们想要做一个定制的迭代器时,我们会生成一个生成器函数:
|
||||
|
||||
```
|
||||
def square_all(numbers):
|
||||
|
||||
for n in numbers:
|
||||
|
||||
yield n**2
|
||||
|
||||
```
|
||||
|
||||
这个生成器函数等价于我们上面所做的类,它的工作原理是一样的。
|
||||
@ -636,14 +530,13 @@ def square_all(numbers):
|
||||
这种 `yield` 语句似乎很神奇,但它非常强大:`yield` 允许我们在调用 `next` 函数之间暂停生成器函数。`yield` 语句是将生成器函数与常规函数分离的东西。
|
||||
|
||||
另一种实现相同迭代器的方法是使用生成器表达式。
|
||||
|
||||
```
|
||||
def square_all(numbers):
|
||||
|
||||
return (n**2 for n in numbers)
|
||||
|
||||
```
|
||||
|
||||
这和我们的生成器函数确实是一样的,但是它使用的语法看起来[像列表一样容易理解][2]。如果你需要在代码中使用惰性迭代,请考虑迭代器,并考虑使用生成器函数或生成器表达式。
|
||||
这和我们的生成器函数确实是一样的,但是它使用的语法看起来[像是一个列表推导一样][2]。如果你需要在代码中使用惰性迭代,请考虑迭代器,并考虑使用生成器函数或生成器表达式。
|
||||
|
||||
### 迭代器如何改进你的代码
|
||||
|
||||
@ -652,33 +545,24 @@ def square_all(numbers):
|
||||
#### 惰性求和
|
||||
|
||||
这是一个 `for` 循环,它对 Django queryset 中的所有工作时间求和:
|
||||
|
||||
```
|
||||
hours_worked = 0
|
||||
|
||||
for event in events:
|
||||
|
||||
if event.is_billable():
|
||||
|
||||
hours_worked += event.duration
|
||||
|
||||
```
|
||||
|
||||
下面是使用生成器表达式进行惰性评估的代码:
|
||||
|
||||
```
|
||||
billable_times = (
|
||||
|
||||
event.duration
|
||||
|
||||
for event in events
|
||||
|
||||
if event.is_billable()
|
||||
|
||||
)
|
||||
|
||||
|
||||
|
||||
hours_worked = sum(billable_times)
|
||||
|
||||
```
|
||||
|
||||
请注意,我们代码的形状发生了巨大变化。
|
||||
@ -688,27 +572,21 @@ hours_worked = sum(billable_times)
|
||||
#### 惰性和打破循环
|
||||
|
||||
这段代码打印出日志文件的前 10 行:
|
||||
|
||||
```
|
||||
for i, line in enumerate(log_file):
|
||||
|
||||
if i >= 10:
|
||||
|
||||
break
|
||||
|
||||
print(line)
|
||||
|
||||
```
|
||||
|
||||
这段代码做了同样的事情,但是我们使用的是 `itertools.islice` 函数来惰性地抓取文件中的前 10 行:
|
||||
|
||||
```
|
||||
from itertools import islice
|
||||
|
||||
first_ten_lines = islice(log_file, 10)
|
||||
|
||||
for line in first_ten_lines:
|
||||
|
||||
print(line)
|
||||
|
||||
```
|
||||
|
||||
我们定义的 `first_ten_lines` 变量是迭代器,同样,使用迭代器允许我们给以前未命名的东西命名(`first_ten_lines`)。命名事物可以使我们的代码更具描述性,更具可读性。
|
||||
@ -722,15 +600,12 @@ for line in first_ten_lines:
|
||||
你可以在标准库和第三方库中找到用于循环的辅助函数,但你也可以自己创建!
|
||||
|
||||
这段代码列出了序列中连续值之间的差值列表。
|
||||
|
||||
```
|
||||
current = readings[0]
|
||||
|
||||
for next_item in readings[1:]:
|
||||
|
||||
differences.append(next_item - current)
|
||||
|
||||
current = next_item
|
||||
|
||||
```
|
||||
|
||||
请注意,这段代码中有一个额外的变量,我们每次循环时都要指定它。还要注意,这段代码只适用于我们可以切片的东西,比如序列。如果 `readings` 是一个生成器,一个 zip 对象或其他任何类型的迭代器,那么这段代码就会失败。
|
||||
@ -738,47 +613,36 @@ for next_item in readings[1:]:
|
||||
让我们编写一个辅助函数来修复代码。
|
||||
|
||||
这是一个生成器函数,它为给定的迭代中的每个项目提供了当前项和下一项:
|
||||
|
||||
```
|
||||
def with_next(iterable):
|
||||
|
||||
"""Yield (current, next_item) tuples for each item in iterable."""
|
||||
|
||||
iterator = iter(iterable)
|
||||
|
||||
current = next(iterator)
|
||||
|
||||
for next_item in iterator:
|
||||
|
||||
yield current, next_item
|
||||
|
||||
current = next_item
|
||||
|
||||
```
|
||||
|
||||
我们从可迭代对象中手动获取一个迭代器,在它上面调用 `next` 来获取第一项,然后循环遍历迭代器获取后续所有的项目,跟踪后一个项目。这个函数不仅适用于序列,而且适用于任何类型迭代。
|
||||
|
||||
这段代码和以前代码是一样的,但是我们使用的是辅助函数而不是手动跟踪 `next_item`:
|
||||
这段代码和以前代码是一样的,但是我们使用的是辅助函数而不是手动跟踪 `next_item`:
|
||||
|
||||
```
|
||||
differences = []
|
||||
|
||||
for current, next_item in with_next(readings):
|
||||
|
||||
differences.append(next_item - current)
|
||||
|
||||
```
|
||||
|
||||
请注意,这段代码不会挂在我们循环周围的 `next_item` 上,`with_next` 生成器函数处理跟踪 `next_item` 的工作。
|
||||
|
||||
还要注意,这段代码已足够紧凑,如果我们愿意,我们甚至可以[将方法复制到列表中来理解][2]。
|
||||
还要注意,这段代码已足够紧凑,如果我们愿意,我们甚至可以[将方法复制到列表推导中来][2]。
|
||||
|
||||
```
|
||||
differences = [
|
||||
|
||||
(next_item - current)
|
||||
|
||||
for current, next_item in with_next(readings)
|
||||
|
||||
]
|
||||
|
||||
```
|
||||
|
||||
### 再次回顾循环问题
|
||||
@ -787,40 +651,34 @@ differences = [
|
||||
|
||||
#### 问题 1:耗尽的迭代器
|
||||
|
||||
这里我们有一个生成器对象 `squares`:
|
||||
这里我们有一个生成器对象 `squares`:
|
||||
|
||||
```
|
||||
>>> numbers = [1, 2, 3, 5, 7]
|
||||
|
||||
>>> squares = (n**2 for n in numbers)
|
||||
|
||||
```
|
||||
|
||||
如果我们把这个生成器传递给 `tuple` 构造函数,我们将会得到它的一个元组:
|
||||
|
||||
```
|
||||
>>> numbers = [1, 2, 3, 5, 7]
|
||||
|
||||
>>> squares = (n**2 for n in numbers)
|
||||
|
||||
>>> tuple(squares)
|
||||
|
||||
(1, 4, 9, 25, 49)
|
||||
|
||||
```
|
||||
|
||||
如果我们试着计算这个生成器中数字的和,使用 `sum`,我们就会得到 `0`:
|
||||
如果我们试着计算这个生成器中数字的和,使用 `sum`,我们就会得到 `0`:
|
||||
|
||||
```
|
||||
>>> sum(squares)
|
||||
|
||||
0
|
||||
|
||||
```
|
||||
|
||||
这个生成器现在是空的:我们已经把它耗尽了。如果我们试着再次创建一个元组,我们会得到一个空元组:
|
||||
|
||||
```
|
||||
>>> tuple(squares)
|
||||
|
||||
()
|
||||
|
||||
```
|
||||
|
||||
生成器是迭代器,迭代器是一次性的。它们就像 Hello Kitty Pez 分配器那样不能重新加载。
|
||||
@ -828,43 +686,35 @@ differences = [
|
||||
#### 问题 2:部分消耗一个迭代器
|
||||
|
||||
再次使用那个生成器对象 `squares`:
|
||||
|
||||
```
|
||||
>>> numbers = [1, 2, 3, 5, 7]
|
||||
|
||||
>>> squares = (n**2 for n in numbers)
|
||||
|
||||
```
|
||||
|
||||
如果我们询问 `9` 是否在 `squares` 生成器中,我们会得到 `True`:
|
||||
如果我们询问 `9` 是否在 `squares` 生成器中,我们会得到 `True`:
|
||||
|
||||
```
|
||||
>>> 9 in squares
|
||||
|
||||
True
|
||||
|
||||
```
|
||||
|
||||
但是我们再次询问相同的问题,我们会得到 `False`:
|
||||
但是我们再次询问相同的问题,我们会得到 `False`:
|
||||
|
||||
```
|
||||
>>> 9 in squares
|
||||
|
||||
False
|
||||
|
||||
```
|
||||
|
||||
当我们询问 `9` 是否在迭代器中时,Python 必须对这个生成器进行循环遍历来找到 `9`。如果我们在检查了 `9` 之后继续循环遍历,我们只会得到最后两个数字,因为我们已经在找到 9 之前消耗了这些数字:
|
||||
|
||||
```
|
||||
>>> numbers = [1, 2, 3, 5, 7]
|
||||
|
||||
>>> squares = (n**2 for n in numbers)
|
||||
|
||||
>>> 9 in squares
|
||||
|
||||
True
|
||||
|
||||
>>> list(squares)
|
||||
|
||||
[25, 49]
|
||||
|
||||
```
|
||||
|
||||
询问迭代器中是否包含某些东西将会部分地消耗迭代器。如果没有循环遍历迭代器,那么是没有办法知道某个东西是否在迭代器中。
|
||||
@ -872,36 +722,29 @@ True
|
||||
#### 问题 3:拆包是迭代
|
||||
|
||||
当你在字典上循环时,你会得到键:
|
||||
|
||||
```
|
||||
>>> counts = {'apples': 2, 'oranges': 1}
|
||||
|
||||
>>> for key in counts:
|
||||
|
||||
... print(key)
|
||||
|
||||
...
|
||||
|
||||
apples
|
||||
|
||||
oranges
|
||||
|
||||
```
|
||||
|
||||
当你对一个字典进行拆包时,你也会得到键:
|
||||
|
||||
```
|
||||
>>> x, y = counts
|
||||
|
||||
>>> x, y
|
||||
|
||||
('apples', 'oranges')
|
||||
|
||||
```
|
||||
|
||||
循环依赖于迭代器协议,可迭代对象拆包也依赖于有迭代器协议。拆包一个字典与在字典上循环遍历是一样的,两者都使用迭代器协议,所以在这两种情况下都得到相同的结果。
|
||||
|
||||
### 回顾
|
||||
|
||||
序列是迭代器,但是不是所有的迭代器都是序列。当有人说“迭代器”这个词时,你只能假设他们的意思是“你可以迭代的东西”。不要假设迭代器可以被循环遍历两次,询问它们的长度,或者索引。
|
||||
序列是迭代器,但是不是所有的迭代器都是序列。当有人说“迭代器”这个词时,你只能假设他们的意思是“你可以迭代的东西”。不要假设迭代器可以被循环遍历两次、询问它们的长度或者索引。
|
||||
|
||||
迭代器是 Python 中最基本的可迭代形式。如果你想在代码中做一个惰性迭代,请考虑迭代器,并考虑使用生成器函数或生成器表达式。
|
||||
|
||||
@ -909,8 +752,15 @@ oranges
|
||||
|
||||
这里有一些我推荐的相关文章和视频:
|
||||
|
||||
本文是基于作者去年在 [DjangoCon AU][6], [PyGotham][7] 和 [North Bay Python][8] 中发表的 Loop Better 演讲。有关更多内容,请参加将于 2018 年 5 月 9 日至 17 日在 Columbus, Ohio 举办的 [PYCON][9]。
|
||||
|
||||
- [Loop Like a Native](https://nedbatchelder.com/text/iter.html), Ned Batchelder 在 PyCon 2013 的讲演
|
||||
- [Loop Better](https://www.youtube.com/watch?v=V2PkkMS2Ack) ,这篇文章是基于这个讲演的
|
||||
- [The Iterator Protocol: How For Loops Work](http://treyhunner.com/2016/12/python-iterator-protocol-how-for-loops-work/),我写的关于迭代器协议的短文
|
||||
- [Comprehensible Comprehensions](https://www.youtube.com/watch?v=5_cJIcgM7rw),关于推导和迭代器表达器的讲演
|
||||
- [Python: Range is Not an Iterator](http://treyhunner.com/2018/02/python-range-is-not-an-iterator/),我关于范围和迭代器的文章
|
||||
- [Looping Like a Pro in Python](https://www.youtube.com/watch?v=u8g9scXeAcI),DB 的 PyCon 2017 讲演
|
||||
|
||||
本文是基于作者去年在 [DjangoCon AU][6]、 [PyGotham][7] 和 [North Bay Python][8] 中发表的 Loop Better 演讲。有关更多内容,请参加将于 2018 年 5 月 9 日至 17 日在 Columbus, Ohio 举办的 [PYCON][9]。
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
@ -919,7 +769,7 @@ via: https://opensource.com/article/18/3/loop-better-deeper-look-iteration-pytho
|
||||
|
||||
作者:[Trey Hunner][a]
|
||||
译者:[MjSeven](https://github.com/MjSeven)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
@ -1,14 +1,13 @@
|
||||
在 CentOS 6 系统上安装最新版 Python3 软件包的 3 种方法
|
||||
======
|
||||
|
||||
CentOS 克隆自 RHEL,无需付费即可使用。CentOS 是一个企业级标准的、前沿的操作系统,被超过 90% 的网络主机托管商采用,因为它提供了技术领先的服务器控制面板 cPanel/WHM。
|
||||
|
||||
该控制面板使得用户无需进入命令行即可通过其管理一切。
|
||||
|
||||
众所周知,RHEL 提供长期支持,出于稳定性考虑,不提供最新版本的软件包。
|
||||
|
||||
如果你想安装的最新版本软件包不在默认源中,你需要手动编译源码安装。
|
||||
|
||||
但手动编译安装的方式有不小的风险,即如果出现新版本,无法升级手动安装的软件包;你不得不重新手动安装。
|
||||
如果你想安装的最新版本软件包不在默认源中,你需要手动编译源码安装。但手动编译安装的方式有不小的风险,即如果出现新版本,无法升级手动安装的软件包;你不得不重新手动安装。
|
||||
|
||||
那么在这种情况下,安装最新版软件包的推荐方法和方案是什么呢?是的,可以通过为系统添加所需的第三方源来达到目的。
|
||||
|
||||
@ -18,19 +17,20 @@ CentOS 克隆自 RHEL,无需付费即可使用。CentOS 是一个企业级标
|
||||
|
||||
在本教程中,我们将向你展示,如何在 CentOS 6 操作系统上安装最新版本的 Python 3 软件包。
|
||||
|
||||
### 方法 1:使用 Software Collections 源 (SCL)
|
||||
### 方法 1:使用 Software Collections 源 (SCL)
|
||||
|
||||
SCL 源目前由 CentOS SIG 维护,除了重新编译构建 Red Hat 的 Software Collections 外,还额外提供一些它们自己的软件包。
|
||||
|
||||
该源中包含不少程序的更高版本,可以在不改变原有旧版本程序包的情况下安装,使用时需要通过 scl 命令调用。
|
||||
该源中包含不少程序的更高版本,可以在不改变原有旧版本程序包的情况下安装,使用时需要通过 `scl` 命令调用。
|
||||
|
||||
运行如下命令可以在 CentOS 上安装 SCL 源:
|
||||
|
||||
```
|
||||
# yum install centos-release-scl
|
||||
|
||||
```
|
||||
|
||||
检查可用的 Python 3 版本:
|
||||
|
||||
```
|
||||
# yum info rh-python35
|
||||
Loaded plugins: fastestmirror, security
|
||||
@ -38,149 +38,148 @@ Loading mirror speeds from cached hostfile
|
||||
* epel: ewr.edge.kernel.org
|
||||
* remi-safe: mirror.team-cymru.com
|
||||
Available Packages
|
||||
Name : rh-python35
|
||||
Arch : x86_64
|
||||
Version : 2.0
|
||||
Release : 2.el6
|
||||
Size : 0.0
|
||||
Repo : installed
|
||||
From repo : centos-sclo-rh
|
||||
Summary : Package that installs rh-python35
|
||||
License : GPLv2+
|
||||
Name : rh-python35
|
||||
Arch : x86_64
|
||||
Version : 2.0
|
||||
Release : 2.el6
|
||||
Size : 0.0
|
||||
Repo : installed
|
||||
From repo : centos-sclo-rh
|
||||
Summary : Package that installs rh-python35
|
||||
License : GPLv2+
|
||||
Description : This is the main package for rh-python35 Software Collection.
|
||||
|
||||
```
|
||||
|
||||
运行如下命令从 scl 源安装可用的最新版 python 3:
|
||||
运行如下命令从 `scl` 源安装可用的最新版 python 3:
|
||||
|
||||
```
|
||||
# yum install rh-python35
|
||||
|
||||
```
|
||||
|
||||
运行如下特殊的 scl 命令,在当前 shell 中启用安装的软件包:
|
||||
运行如下特殊的 `scl` 命令,在当前 shell 中启用安装的软件包:
|
||||
|
||||
```
|
||||
# scl enable rh-python35 bash
|
||||
|
||||
```
|
||||
|
||||
运行如下命令检查安装的 python3 版本:
|
||||
|
||||
```
|
||||
# python --version
|
||||
Python 3.5.1
|
||||
|
||||
```
|
||||
|
||||
运行如下命令获取系统已安装的 SCL 软件包列表:
|
||||
|
||||
```
|
||||
# scl -l
|
||||
rh-python35
|
||||
|
||||
```
|
||||
|
||||
### 方法 2:使用 EPEL 源 (Extra Packages for Enterprise Linux)
|
||||
### 方法 2:使用 EPEL 源 (Extra Packages for Enterprise Linux)
|
||||
|
||||
EPEL 是 Extra Packages for Enterprise Linux 的缩写,该源由 Fedora SIG (Special Interest Group) 维护。
|
||||
EPEL 是 Extra Packages for Enterprise Linux 的缩写,该源由 Fedora SIG (Special Interest Group)维护。
|
||||
|
||||
该 SIG 为企业级 Linux 创建、维护并管理一系列高品质补充软件包,受益的企业级 Linux 发行版包括但不限于红帽企业级 Linux (RHEL), CentOS, Scientific Linux (SL) 和 Oracle Linux (OL)等。
|
||||
该 SIG 为企业级 Linux 创建、维护并管理了一系列高品质补充软件包,受益的企业级 Linux 发行版包括但不限于红帽企业级 Linux (RHEL)、 CentOS、 Scientific Linux (SL) 和 Oracle Linux (OL)等。
|
||||
|
||||
EPEL 通常基于 Fedora 对应代码提供软件包,不会与企业级 Linux 发行版中的基础软件包冲突或替换其中的软件包。
|
||||
|
||||
**推荐阅读:** [在 RHEL, CentOS, Oracle Linux 或 Scientific Linux 上安装启用 EPEL 源][1]
|
||||
|
||||
EPEL 软件包位于 CentOS 的 Extra 源中,已经默认启用,故我们只需运行如下命令即可:
|
||||
|
||||
```
|
||||
# yum install epel-release
|
||||
|
||||
```
|
||||
|
||||
检查可用的 python 3 版本:
|
||||
|
||||
```
|
||||
# yum --disablerepo="*" --enablerepo="epel" info python34
|
||||
Loaded plugins: fastestmirror, security
|
||||
Loading mirror speeds from cached hostfile
|
||||
* epel: ewr.edge.kernel.org
|
||||
Available Packages
|
||||
Name : python34
|
||||
Arch : x86_64
|
||||
Version : 3.4.5
|
||||
Release : 4.el6
|
||||
Size : 50 k
|
||||
Repo : epel
|
||||
Summary : Version 3 of the Python programming language aka Python 3000
|
||||
URL : http://www.python.org/
|
||||
License : Python
|
||||
Name : python34
|
||||
Arch : x86_64
|
||||
Version : 3.4.5
|
||||
Release : 4.el6
|
||||
Size : 50 k
|
||||
Repo : epel
|
||||
Summary : Version 3 of the Python programming language aka Python 3000
|
||||
URL : http://www.python.org/
|
||||
License : Python
|
||||
Description : Python 3 is a new version of the language that is incompatible with the 2.x
|
||||
: line of releases. The language is mostly the same, but many details, especially
|
||||
: how built-in objects like dictionaries and strings work, have changed
|
||||
: considerably, and a lot of deprecated features have finally been removed.
|
||||
|
||||
|
||||
: line of releases. The language is mostly the same, but many details, especially
|
||||
: how built-in objects like dictionaries and strings work, have changed
|
||||
: considerably, and a lot of deprecated features have finally been removed.
|
||||
```
|
||||
|
||||
运行如下命令从 EPEL 源安装可用的最新版 python 3 软件包:
|
||||
|
||||
```
|
||||
# yum --disablerepo="*" --enablerepo="epel" install python34
|
||||
|
||||
```
|
||||
|
||||
默认情况下并不会安装 pip 和 setuptools,我们需要运行如下命令手动安装:
|
||||
默认情况下并不会安装 `pip` 和 `setuptools`,我们需要运行如下命令手动安装:
|
||||
|
||||
```
|
||||
# curl -O https://bootstrap.pypa.io/get-pip.py
|
||||
% Total % Received % Xferd Average Speed Time Time Time Current
|
||||
Dload Upload Total Spent Left Speed
|
||||
100 1603k 100 1603k 0 0 2633k 0 --:--:-- --:--:-- --:--:-- 4816k
|
||||
% Total % Received % Xferd Average Speed Time Time Time Current
|
||||
Dload Upload Total Spent Left Speed
|
||||
100 1603k 100 1603k 0 0 2633k 0 --:--:-- --:--:-- --:--:-- 4816k
|
||||
|
||||
# /usr/bin/python3.4 get-pip.py
|
||||
Collecting pip
|
||||
Using cached https://files.pythonhosted.org/packages/0f/74/ecd13431bcc456ed390b44c8a6e917c1820365cbebcb6a8974d1cd045ab4/pip-10.0.1-py2.py3-none-any.whl
|
||||
Using cached https://files.pythonhosted.org/packages/0f/74/ecd13431bcc456ed390b44c8a6e917c1820365cbebcb6a8974d1cd045ab4/pip-10.0.1-py2.py3-none-any.whl
|
||||
Collecting setuptools
|
||||
Downloading https://files.pythonhosted.org/packages/8c/10/79282747f9169f21c053c562a0baa21815a8c7879be97abd930dbcf862e8/setuptools-39.1.0-py2.py3-none-any.whl (566kB)
|
||||
100% |████████████████████████████████| 573kB 4.0MB/s
|
||||
Downloading https://files.pythonhosted.org/packages/8c/10/79282747f9169f21c053c562a0baa21815a8c7879be97abd930dbcf862e8/setuptools-39.1.0-py2.py3-none-any.whl (566kB)
|
||||
100% |████████████████████████████████| 573kB 4.0MB/s
|
||||
Collecting wheel
|
||||
Downloading https://files.pythonhosted.org/packages/1b/d2/22cde5ea9af055f81814f9f2545f5ed8a053eb749c08d186b369959189a8/wheel-0.31.0-py2.py3-none-any.whl (41kB)
|
||||
100% |████████████████████████████████| 51kB 8.0MB/s
|
||||
Downloading https://files.pythonhosted.org/packages/1b/d2/22cde5ea9af055f81814f9f2545f5ed8a053eb749c08d186b369959189a8/wheel-0.31.0-py2.py3-none-any.whl (41kB)
|
||||
100% |████████████████████████████████| 51kB 8.0MB/s
|
||||
Installing collected packages: pip, setuptools, wheel
|
||||
Successfully installed pip-10.0.1 setuptools-39.1.0 wheel-0.31.0
|
||||
|
||||
```
|
||||
|
||||
运行如下命令检查已安装的 python3 版本:
|
||||
|
||||
```
|
||||
# python3 --version
|
||||
Python 3.4.5
|
||||
|
||||
```
|
||||
|
||||
### 方法 3:使用 IUS 社区源
|
||||
|
||||
IUS 社区是 CentOS 社区批准的第三方 RPM 源,为企业级 Linux (RHEL 和 CentOS) 5, 6 和 7 版本提供最新上游版本的 PHP, Python, MySQL 等软件包。
|
||||
IUS 社区是 CentOS 社区批准的第三方 RPM 源,为企业级 Linux (RHEL 和 CentOS) 5、 6 和 7 版本提供最新上游版本的 PHP、 Python、 MySQL 等软件包。
|
||||
|
||||
IUS 社区源依赖于 EPEL 源,故我们需要先安装 EPEL 源,然后再安装 IUS 社区源。按照下面的步骤安装启用 EPEL 源和 IUS 社区源,利用该 RPM 系统安装软件包。
|
||||
|
||||
**推荐阅读:** [在 RHEL 或 CentOS 上安装启用 IUS 社区源][2]
|
||||
|
||||
EPEL 软件包位于 CentOS 的 Extra 源中,已经默认启用,故我们只需运行如下命令即可:
|
||||
|
||||
```
|
||||
# yum install epel-release
|
||||
|
||||
```
|
||||
|
||||
下载 IUS 社区源安装脚本:
|
||||
|
||||
```
|
||||
# curl 'https://setup.ius.io/' -o setup-ius.sh
|
||||
% Total % Received % Xferd Average Speed Time Time Time Current
|
||||
Dload Upload Total Spent Left Speed
|
||||
100 1914 100 1914 0 0 6563 0 --:--:-- --:--:-- --:--:-- 133k
|
||||
|
||||
% Total % Received % Xferd Average Speed Time Time Time Current
|
||||
Dload Upload Total Spent Left Speed
|
||||
100 1914 100 1914 0 0 6563 0 --:--:-- --:--:-- --:--:-- 133k
|
||||
```
|
||||
|
||||
安装启用 IUS 社区源:
|
||||
|
||||
```
|
||||
# sh setup-ius.sh
|
||||
|
||||
```
|
||||
|
||||
检查可用的 python 3 版本:
|
||||
|
||||
```
|
||||
# yum --enablerepo=ius info python36u
|
||||
Loaded plugins: fastestmirror, security
|
||||
@ -189,46 +188,45 @@ Loading mirror speeds from cached hostfile
|
||||
* ius: mirror.team-cymru.com
|
||||
* remi-safe: mirror.team-cymru.com
|
||||
Available Packages
|
||||
Name : python36u
|
||||
Arch : x86_64
|
||||
Version : 3.6.5
|
||||
Release : 1.ius.centos6
|
||||
Size : 55 k
|
||||
Repo : ius
|
||||
Summary : Interpreter of the Python programming language
|
||||
URL : https://www.python.org/
|
||||
License : Python
|
||||
Name : python36u
|
||||
Arch : x86_64
|
||||
Version : 3.6.5
|
||||
Release : 1.ius.centos6
|
||||
Size : 55 k
|
||||
Repo : ius
|
||||
Summary : Interpreter of the Python programming language
|
||||
URL : https://www.python.org/
|
||||
License : Python
|
||||
Description : Python is an accessible, high-level, dynamically typed, interpreted programming
|
||||
: language, designed with an emphasis on code readability.
|
||||
: It includes an extensive standard library, and has a vast ecosystem of
|
||||
: third-party libraries.
|
||||
:
|
||||
: The python36u package provides the "python3.6" executable: the reference
|
||||
: interpreter for the Python language, version 3.
|
||||
: The majority of its standard library is provided in the python36u-libs package,
|
||||
: which should be installed automatically along with python36u.
|
||||
: The remaining parts of the Python standard library are broken out into the
|
||||
: python36u-tkinter and python36u-test packages, which may need to be installed
|
||||
: separately.
|
||||
:
|
||||
: Documentation for Python is provided in the python36u-docs package.
|
||||
:
|
||||
: Packages containing additional libraries for Python are generally named with
|
||||
: the "python36u-" prefix.
|
||||
|
||||
: language, designed with an emphasis on code readability.
|
||||
: It includes an extensive standard library, and has a vast ecosystem of
|
||||
: third-party libraries.
|
||||
:
|
||||
: The python36u package provides the "python3.6" executable: the reference
|
||||
: interpreter for the Python language, version 3.
|
||||
: The majority of its standard library is provided in the python36u-libs package,
|
||||
: which should be installed automatically along with python36u.
|
||||
: The remaining parts of the Python standard library are broken out into the
|
||||
: python36u-tkinter and python36u-test packages, which may need to be installed
|
||||
: separately.
|
||||
:
|
||||
: Documentation for Python is provided in the python36u-docs package.
|
||||
:
|
||||
: Packages containing additional libraries for Python are generally named with
|
||||
: the "python36u-" prefix.
|
||||
```
|
||||
|
||||
运行如下命令从 IUS 源安装最新可用版本的 python 3 软件包:
|
||||
|
||||
```
|
||||
# yum --enablerepo=ius install python36u
|
||||
|
||||
```
|
||||
|
||||
运行如下命令检查已安装的 python3 版本:
|
||||
|
||||
```
|
||||
# python3.6 --version
|
||||
Python 3.6.5
|
||||
|
||||
```
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
@ -238,7 +236,7 @@ via: https://www.2daygeek.com/3-methods-to-install-latest-python3-package-on-cen
|
||||
作者:[PRAKASH SUBRAMANIAN][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[pinewall](https://github.com/pinewall)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
@ -1,124 +0,0 @@
|
||||
Translating by FelixYFZ 7 leadership rules for the DevOps age
|
||||
======
|
||||
|
||||

|
||||
|
||||
If [DevOps][1] is ultimately more about culture than any particular technology or platform, then remember this: There isn't a finish line. It's about continuous change and improvement - and the C-suite doesn't get a pass.
|
||||
|
||||
Rather, leaders need to [revise some of their traditional approaches][2] if they expect DevOps to help drive the outcomes they seek. Let's consider seven ideas for more effective IT leadership in the DevOps era.
|
||||
|
||||
### 1. Say "yes" to failure
|
||||
|
||||
The word "failure" has long had very specific connotations in IT, and they're almost universally bad: server failure, backup failure, hard drive failure - you get the picture.
|
||||
|
||||
A healthy DevOps culture, however, depends upon redefining failure - IT leaders should rewrite their thesaurus to make the word synonymous with "opportunity."
|
||||
|
||||
"Prior to DevOps, we had a culture of punishing failure," says Robert Reeves, CTO and co-founder of [Datical][3]. "The only learning we had was to avoid mistakes. The number one way to avoid mistakes in IT is to not change anything: Don't accelerate the release schedule, don't move to the cloud, don't do anything differently!"
|
||||
|
||||
That's a playbook for a bygone era and, as Reeves puts plainly, it doesn't work. In fact, that kind of stasis is actual failure.
|
||||
|
||||
"Companies that release slowly and avoid the cloud are paralyzed by fear - and they will fail," Reeves says. "IT leaders must embrace failure as an opportunity. Humans not only learn from their mistakes, they learn from others' mistakes. A culture of openness and ['psychological safety'][4] fosters learning and improvement."
|
||||
|
||||
**[ Related article: [Why agile leaders must move beyond talking about "failure."][5] ]**
|
||||
|
||||
### 2. Live, eat, and breathe DevOps in the C-suite
|
||||
|
||||
While DevOps culture can certainly grow organically in all directions, companies that are shifting from monolithic, siloed IT practices - and likely encountering headwinds en route - need total buy-in from executive leadership. Without it, you're sending mixed messages and likely emboldening those who'd rather push a _but this is the way we 've always done things_ agenda. [Culture change is hard][6]; people need to see leadership fully invested in that change for it to actually happen.
|
||||
|
||||
"Top management must fully support DevOps in order for it to be successful in delivering the benefits," says Derek Choy, CIO at [Rainforest QA][7].
|
||||
|
||||
Becoming a DevOps shop. Choy notes, touches pretty much everything in the organization, from technical teams to tools to processes to roles and responsibilities.
|
||||
|
||||
"Without unified sponsorship from top management, DevOps implementation will not be successful," Choy says. "Therefore, it is important to have leaders aligned at the top level before transitioning to DevOps."
|
||||
|
||||
### 3. Don 't just declare "DevOps" - define it
|
||||
|
||||
Even in IT organizations that have welcomed DevOps with open arms, it's possible that's not everyone's on the same page.
|
||||
|
||||
**[Read our related article,**[ **3 areas where DevOps and CIOs must get on the same page**][8] **.]**
|
||||
|
||||
One fundamental reason for such disconnects: People might be operating with different definitions for what the term even means.
|
||||
|
||||
"DevOps can mean different things to different people," Choy says. "It is important for C-level [and] VP-level execs to define the goals of DevOps, clearly stating the expected outcome, understand how this outcome can benefit the business and be able to measure and report on success along the way."
|
||||
|
||||
Indeed, beyond the baseline definition and vision, DevOps requires ongoing and frequent communication, not just in the trenches but throughout the organization. IT leaders must make that a priority.
|
||||
|
||||
"Inevitably, there will be hiccups, there will be failures and disruptions to the business," Choy says. "Leaders need to clearly communicate the journey to the rest of the company and what they can expect as part of the process."
|
||||
|
||||
### 4.DevOps is as much about business as technology
|
||||
|
||||
IT leaders running successful DevOps shops have embraced its culture and practices as a business strategy as much as an approach to building and operating software. DevOps culture is a great enabler of IT's shift from support arm to strategic business unit.
|
||||
|
||||
"IT leaders must shift their thinking and approach from being cost/service centers to driving business outcomes, and a DevOps culture helps speed up those outcomes via automation and stronger collaboration," says Mike Kail, CTO and co-founder at [CYBRIC][9].
|
||||
|
||||
Indeed, this is a strong current that runs through much of these new "rules" for leading in the age of DevOps.
|
||||
|
||||
"Promoting innovation and encouraging team members to take smart risks is a key part of a DevOps culture and IT leaders need to clearly communicate that on a continuous basis," Kail says.
|
||||
|
||||
"An effective IT leader will need to be more engaged with the business than ever before," says Evan Callendar, director, performance services at [West Monroe Partners][10]. "Gone are the days of yearly or quarterly reviews - you need to welcome the [practice of] [bi-weekly backlog grooming][11]. The ability to think strategically at the year level, but interact at the sprint level, will be rewarded when business expectations are met."
|
||||
|
||||
### 5. Change anything that hampers DevOps goals
|
||||
|
||||
|
||||
While DevOps veterans generally agree that DevOps is much more a matter of culture than technology, success does depend on enabling that culture with the right processes and tools. Declaring your department a DevOps shop while resisting the necessary changes to processes or technologies is like buying a Ferrari but keeping the engine from your 20-year-old junker that billows smoke each time you turn the key.
|
||||
|
||||
Exhibit A: [Automation][12]. It's critical parallel strategy for DevOps success.
|
||||
|
||||
"IT leadership has to put an emphasis on automation," Callendar says. "This will be an upfront investment, but without it, DevOps simply will engulf itself with inefficiency and lack of delivery."
|
||||
|
||||
Automation is a fundamental, but change doesn't stop there.
|
||||
|
||||
"Leaders need to push for automation, monitoring, and a continuous delivery process. This usually means changes to many existing practices, processes, team structures, [and] roles," Choy says. "Leaders need to be willing to change anything that'll hinder the team's ability to fully automate the process."
|
||||
|
||||
### 6. Rethink team structure and performance metrics
|
||||
|
||||
While we're on the subject of change...if that org chart collecting dust on your desktop is the same one you've been plugging names into for the better part of a decade (or more), it's time for an overhaul.
|
||||
|
||||
"IT executives need to take a completely different approach to organizational structure in this new era of DevOps culture," Kail says. "Remove strict team boundaries, which tend to hamper collaboration, and allow for the teams to be self-organizing and agile."
|
||||
|
||||
Kail says this kind of rethinking can and should extend to other areas in the DevOps age, too, including how you measure individual and team success, and even how you interact with people.
|
||||
|
||||
"Measure initiatives in terms of business outcomes and overall positive impact," Kail advises. "Finally, and something that I believe to be the most important aspect of management: Be empathetic."
|
||||
|
||||
Beware easily collected measurements that are not truly DevOps metrics, writes [Red Hat ][13]technology evangelist Gordon Haff. "DevOps metrics should be tied to business outcomes in some manner," he notes. "You probably don't really care about how many lines of code your developers write, whether a server had a hardware failure overnight, or how comprehensive your test coverage is. In fact, you may not even directly care about the responsiveness of your website or the rapidity of your updates. But you do care to the degree such metrics can be correlated with customers abandoning shopping carts or leaving for a competitor." See his full article, [DevOps metrics: Are you measuring what matters?][14]
|
||||
|
||||
### 7. Chuck conventional wisdom out the window
|
||||
|
||||
If the DevOps age requires new ways of thinking about IT leadership, it follows that some of the old ways need to be retired. But which ones?
|
||||
|
||||
"To be honest, all of them," Kail says. "Get rid of the 'because that's the way we've always done things' mindset. The transition to a culture of DevOps is a complete paradigm shift, not a few subtle changes to the old days of Waterfall and Change Advisory Boards."
|
||||
|
||||
Indeed, IT leaders recognize that real transformation requires more than minor touch-ups to old approaches. Often, it requires a total reboot of a previous process or strategy.
|
||||
|
||||
Callendar of West Monroe Partners shares a parting example of legacy leadership thinking that hampers DevOps: Failing to embrace hybrid IT models and modern infrastructure approaches such as containers and microservices.
|
||||
|
||||
"One of the big rules I see going out the window is architecture consolidation, or the idea that long-term maintenance is cheaper if done within a homogenous environment," Callendar says.
|
||||
|
||||
**Want more wisdom like this, IT leaders? [Sign up for our weekly email newsletter][15].**
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://enterprisersproject.com/article/2018/1/7-leadership-rules-devops-age
|
||||
|
||||
作者:[Kevin Casey][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://enterprisersproject.com/user/kevin-casey
|
||||
[1]:https://enterprisersproject.com/tags/devops
|
||||
[2]:https://enterprisersproject.com/article/2017/7/devops-requires-dumping-old-it-leadership-ideas
|
||||
[3]:https://www.datical.com/
|
||||
[4]:https://rework.withgoogle.com/guides/understanding-team-effectiveness/steps/foster-psychological-safety/
|
||||
[5]:https://enterprisersproject.com/article/2017/10/why-agile-leaders-must-move-beyond-talking-about-failure?sc_cid=70160000000h0aXAAQ
|
||||
[6]:https://enterprisersproject.com/article/2017/10/how-beat-fear-and-loathing-it-change
|
||||
[7]:https://www.rainforestqa.com/
|
||||
[8]:https://enterprisersproject.com/article/2018/1/3-areas-where-devops-and-cios-must-get-same-page
|
||||
[9]:https://www.cybric.io/
|
||||
[10]:http://www.westmonroepartners.com/
|
||||
[11]:https://www.scrumalliance.org/community/articles/2017/february/product-backlog-grooming
|
||||
[12]:https://www.redhat.com/en/topics/automation?intcmp=701f2000000tjyaAAA
|
||||
[13]:https://www.redhat.com/en?intcmp=701f2000000tjyaAAA
|
||||
[14]:https://enterprisersproject.com/article/2017/7/devops-metrics-are-you-measuring-what-matters
|
||||
[15]:https://enterprisersproject.com/email-newsletter?intcmp=701f2000000tsjPAAQ
|
@ -1,4 +1,4 @@
|
||||
Why DevSecOps matters to IT leaders
|
||||
Translating by FelixYFZ Why DevSecOps matters to IT leaders
|
||||
======
|
||||
|
||||

|
||||
|
@ -1,155 +0,0 @@
|
||||
translating by wyxplus
|
||||
Things You Should Know About Ubuntu 18.04
|
||||
======
|
||||
[Ubuntu 18.04 release][1] is just around the corner. I can see lots of questions from Ubuntu users in various Facebook groups and forums. I also organized Q&A sessions on Facebook and Instagram to know what Ubuntu users are wondering about Ubuntu 18.04.
|
||||
|
||||
I have tried to answer those frequently asked questions about Ubuntu 18.04 here. I hope it helps clear your doubts if you had any. And if you still have questions, feel free to ask in the comment section below.
|
||||
|
||||
### What to expect in Ubuntu 18.04
|
||||
|
||||
![Ubuntu 18.04 Frequently Asked Questions][2]
|
||||
|
||||
Just for clarification, some of the answers here are influenced by my personal opinion. If you are an experienced/aware Ubuntu user, some of the questions may sound silly to you. If that’s case, just ignore those questions.
|
||||
|
||||
#### Can I install Unity on Ubuntu 18.04?
|
||||
|
||||
Yes, you can.
|
||||
|
||||
Canonical knows that there are people who simply loved Unity. This is why it has made Unity 7 available in the Universe repository. This is a community maintained edition and Ubuntu doesn’t develop it directly.
|
||||
|
||||
I advise using the default GNOME first and if you really cannot tolerate it, then go on [installing Unity on Ubuntu 18.04][3].
|
||||
|
||||
#### What GNOME version does it have?
|
||||
|
||||
At the time of its release, Ubuntu 18.04 has GNOME 3.28.
|
||||
|
||||
#### Can I install vanilla GNOME on it?
|
||||
|
||||
Yes, you can.
|
||||
|
||||
Existing GNOME users might not like the Unity resembling, customized GNOME desktop in Ubuntu 18.04. There are some packages available in Ubuntu’s main and universe repositories that allows you to [install vanilla GNOME on Ubuntu 18.04][4].
|
||||
|
||||
#### Has the memory leak in GNOME fixed?
|
||||
|
||||
Yes. The [infamous memory leak in GNOME 3.28][5] has been fixed and [Ubuntu is already testing the fix][6].
|
||||
|
||||
Just to clarify, the memory leak was not caused by Ubuntu. It was/is impacting all Linux distributions that use GNOME 3.28. A new patch was released under GNOME 3.28.1 to fix this memory leak.
|
||||
|
||||
#### How long will Ubuntu 18.04 be supported?
|
||||
|
||||
It is a long-term support (LTS) release and like any LTS release, it will be supported for five years. Which means that Ubuntu 18.04 will get security and maintenance updates until April 2023. This is also true for all participating flavors except Ubuntu Studio.
|
||||
|
||||
#### When will Ubuntu 18.04 be released?
|
||||
|
||||
Ubuntu 18.04 LTS has been released on 26th April. All the participating flavors like Kubuntu, Lubuntu, Xubuntu, Budgie, MATE etc will have their 18.04 release available on the same day.
|
||||
|
||||
It seems [Ubuntu Studio will not have 18.04 as LTS release][7].
|
||||
|
||||
#### Is it possible to upgrade to Ubuntu 18.04 from 16.04/17.10? Can I upgrade from Ubuntu 16.04 with Unity to Ubuntu 18.04 with GNOME?
|
||||
|
||||
Yes, absolutely. Once Ubuntu 18.04 LTS is released, you can easily upgrade to the new version.
|
||||
|
||||
If you are using Ubuntu 17.10, make sure that in Software & Updates -> Updates, the ‘Notify me of a new Ubuntu version’ is set to ‘For any new version’.
|
||||
|
||||
![Get notified for a new version in Ubuntu][8]
|
||||
|
||||
If you are using Ubuntu 16.04, make sure that in Software & Updates -> Updates, the ‘Notify me of a new Ubuntu version’ is set to ‘For long-term support versions’.
|
||||
|
||||
![Ubuntu 18.04 upgrade from Ubuntu 16.04][9]
|
||||
|
||||
You should get system notification about the availability of the new versions. After that, upgrading to Ubuntu 18.04 is a matter of clicks.
|
||||
|
||||
Even if Ubuntu 16.04 was Unity, you can still [upgrade to Ubuntu 18.04][10] GNOME.
|
||||
|
||||
#### What does upgrading to Ubuntu 18.04 mean? Will I lose my data?
|
||||
|
||||
If you are using Ubuntu 17.10 or Ubuntu 16.04, sooner or later, Ubuntu will notify you that Ubuntu 18.04 is available. If you have a good internet connection that can download 1.5 Gb of data, you can upgrade to Ubuntu 18.04 in a few clicks and in under 30 minutes.
|
||||
|
||||
You don’t need to create a new USB and do a fresh install. Once the upgrade procedure finishes, you’ll have the new Ubuntu version available.
|
||||
|
||||
Normally, your data, documents etc are safe in the upgrade procedure. However, keeping a backup of your important documents is always a good idea.
|
||||
|
||||
#### When will I get to upgrade to Ubuntu 18.04?
|
||||
|
||||
If you are using Ubuntu 17.10 and have correct update settings in place (as mentioned in the previous section), you should be notified for upgrading to Ubuntu 18.04 within a few days of Ubuntu 18.04 release. Since Ubuntu servers encounter heavy load on the release day, not everyone gets the upgrade the same day.
|
||||
|
||||
For Ubuntu 16.04 users, it may take some weeks before they are officially notified of the availability of Ubuntu 18.04. Usually, this will happen after the first point release Ubuntu 18.04.1. This point release fixes the newly discovered bugs in 18.04.
|
||||
|
||||
#### If I upgrade to Ubuntu 18.04 can I downgrade to 17.10 or 16.04?
|
||||
|
||||
No, you cannot. While upgrading to the newer version is easy, there is no option to downgrade. If you want to go back to Ubuntu 16.04, you’ll have to do a fresh install.
|
||||
|
||||
#### Can I use Ubuntu 18.04 on 32-bit systems?
|
||||
|
||||
Yes and no.
|
||||
|
||||
If you are already using the 32-bit version of Ubuntu 16.04 or 17.10, you may still get to upgrade to Ubuntu 18.04. However, you won’t find Ubuntu 18.04 bit ISO in 32-bit format anymore. In other words, you cannot do a fresh install of the 32-bit version of Ubuntu 18.04 GNOME.
|
||||
|
||||
The good news here is that other official flavors like Ubuntu MATE, Lubuntu etc still have the 32-bit ISO of their new versions.
|
||||
|
||||
In any case, if you have a 32-bit system, chances are that your system is weak on hardware. You’ll be better off using lightweight [Ubuntu MATE][11] or [Lubuntu][12] on such system.
|
||||
|
||||
#### Where can I download Ubuntu 18.04?
|
||||
|
||||
Once 18.04 is released, you can get the ISO image of Ubuntu 18.04 from its website. You have both direct download and torrent options. Other official flavors will be available on their official websites.
|
||||
|
||||
#### Should I do a fresh install of Ubuntu 18.04 or upgrade to it from 16.04/17.10?
|
||||
|
||||
If you have a choice, make a backup of your data and do a fresh install of Ubuntu 18.04.
|
||||
|
||||
Upgrading to 18.04 from an existing version is a convenient option. However, in my opinion, it still keeps some traces/packages of the older version. A fresh install is always cleaner.
|
||||
|
||||
For a fresh install, should I install Ubuntu 16.04 or Ubuntu 18.04?
|
||||
|
||||
If you are going to install Ubuntu on a system, go for Ubuntu 18.04 instead of 16.04.
|
||||
|
||||
Both of them are long-term support release and will be supported for a long time. Ubuntu 16.04 will get maintenance and security updates until 2021 and 18.04 until 2023.
|
||||
|
||||
However, I would suggest that you use Ubuntu 18.04. Any LTS release gets [hardware updates for a limited time][13] (two and a half years I think). After that, it only gets maintenance updates. If you have newer hardware, you’ll get better support in 18.04.
|
||||
|
||||
Also, many application developers will start focusing on Ubuntu 18.04 soon. Newly created PPAs might only support 18.04 in a few months. Using 18.04 has its advantages over 16.04.
|
||||
|
||||
#### Will it be easier to install printer-scanner drivers instead of using the CLI?
|
||||
|
||||
I am not an expert when it comes to printers so my opinion is based on my limited knowledge in this field. Most of the new printers support [IPP protocol][14] and thus they should be well supported in Ubuntu 18.04. I cannot say the same about older printers.
|
||||
|
||||
#### Does Ubuntu 18.04 have better support for Realtek and other WiFi adapters?
|
||||
|
||||
No specific information on this part.
|
||||
|
||||
#### What are the system requirements for Ubuntu 18.04?
|
||||
|
||||
For the default GNOME version, you should have [4 GB of RAM for a comfortable use][15]. A processor released in last 8 years will work as well. Anything older than that should use a [lightweight Linux distribution][16] such as [Lubuntu][12].
|
||||
|
||||
#### Any other questions about Ubuntu 18.04?
|
||||
|
||||
If you have any other doubts regarding Ubuntu 18.04, please feel free to leave a comment below. If you think some other information should be added to the list, please let me know.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/ubuntu-18-04-faq/
|
||||
|
||||
作者:[Abhishek Prakash][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://itsfoss.com/author/abhishek/
|
||||
[1]:https://itsfoss.com/ubuntu-18-04-release-features/
|
||||
[2]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/04/ubuntu-18-04-faq-800x450.png
|
||||
[3]:https://itsfoss.com/use-unity-ubuntu-17-10/
|
||||
[4]:https://itsfoss.com/vanilla-gnome-ubuntu/
|
||||
[5]:https://feaneron.com/2018/04/20/the-infamous-gnome-shell-memory-leak/
|
||||
[6]:https://community.ubuntu.com/t/help-test-memory-leak-fixes-in-18-04-lts/5251
|
||||
[7]:https://www.omgubuntu.co.uk/2018/04/ubuntu-studio-plans-to-reboot
|
||||
[8]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/03/upgrade-ubuntu-2.jpeg
|
||||
[9]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2017/10/ubuntu-18-04-upgrade-settings-800x379.png
|
||||
[10]:https://itsfoss.com/upgrade-ubuntu-version/
|
||||
[11]:https://ubuntu-mate.org/
|
||||
[12]:https://lubuntu.net/
|
||||
[13]:https://www.ubuntu.com/info/release-end-of-life
|
||||
[14]:https://www.pwg.org/ipp/everywhere.html
|
||||
[15]:https://help.ubuntu.com/community/Installation/SystemRequirements
|
||||
[16]:https://itsfoss.com/lightweight-linux-beginners/
|
@ -1,78 +0,0 @@
|
||||
Translating by MjSeven
|
||||
|
||||
|
||||
4 Firefox extensions to install now
|
||||
======
|
||||

|
||||
As I mentioned in my [original article][1] on Firefox extensions, the web browser has become a critical component of the computing experience for many users. Modern browsers have evolved into powerful and extensible platforms, and extensions can add or modify their functionality. Extensions for Firefox are built using the WebExtensions API, a cross-browser development system.
|
||||
|
||||
In the first article, I asked readers: "Which extensions should you install?" To reiterate, that decision largely comes down to how you use your browser, your views on privacy, how much you trust extension developers, and other personal preferences. Since that article was published, one extension I recommended (Xmarks) has been discontinued. Additionally, that article received a ton of feedback that has been taken into account for this update.
|
||||
|
||||
Once again, I'd like to point out that browser extensions often require the ability to read and/or change everything on the web pages you visit. You should consider the ramifications of this very carefully. If an extension has modify access to all the web pages you visit, it could act as a keylogger, intercept credit card information, track you online, insert advertisements, and perform a variety of other nefarious activities. That doesn't mean every extension will surreptitiously do these things, but you should carefully consider the installation source, the permissions involved, your risk profile, and other factors before you install any extension. Keep in mind you can use profiles to manage how an extension impacts your attack surface—for example, using a dedicated profile with no extensions to perform tasks such as online banking.
|
||||
|
||||
With that in mind, here are four open source Firefox extensions you may want to consider.
|
||||
|
||||
### uBlock Origin
|
||||
|
||||
![ublock origin ad blocker screenshot][2]
|
||||
|
||||
My first recommendation remains unchanged. [uBlock Origin][3] is a fast, low memory, wide-spectrum blocker that allows you to not only block ads but also enforce your own content filtering. The default behavior of uBlock Origin is to block ads, trackers, and malware sites using multiple, predefined filter lists. From there it allows you to arbitrarily add lists and rules, or even lock down to a default-deny mode. Despite being powerful, the extension has proven to be efficient and performant. It continues to be updated regularly and is one of the best options available for this functionality.
|
||||
|
||||
### Privacy Badger
|
||||
|
||||
![privacy badger ad blocker][4]
|
||||
|
||||
My second recommendation also remains unchanged. If anything, privacy has been brought even more to the forefront since my previous article, making this extension an easy recommendation. As the name indicates, [Privacy Badger][5] is a privacy-focused extension that blocks ads and other third-party trackers. It's a project of the Electronic Freedom Foundation, which says:
|
||||
|
||||
> "Privacy Badger was born out of our desire to be able to recommend a single extension that would automatically analyze and block any tracker or ad that violated the principle of user consent; which could function well without any settings, knowledge, or configuration by the user; which is produced by an organization that is unambiguously working for its users rather than for advertisers; and which uses algorithmic methods to decide what is and isn't tracking."
|
||||
|
||||
Why is Privacy Badger on this list when the previous item may seem similar? A couple reasons. The first is that it fundamentally works differently than uBlock Origin. The second is that a practice of defense in depth is a sound policy to follow. Speaking of defense in depth, the EFF also maintains [HTTPS Everywhere][6] to automatically ensure https is used for many major websites. When you're installing Privacy Badger, you may want to consider HTTPS Everywhere as well.
|
||||
|
||||
In case you were starting to think this article was simply going to be a rehash of the last one, here's where my recommendations diverge.
|
||||
|
||||
### Bitwarden
|
||||
|
||||
![Bitwarden][7]
|
||||
|
||||
When recommending LastPass in the previous article, I mentioned it was likely going to be a controversial selection. That certainly proved true. Whether you should use a password manager at all—and if you do, whether you should choose one that has a browser plugin—is a hotly debated topic, and the answer very much depends on your personal risk profile. I asserted that most casual computer users should use one because it's much better than the most common alternative: using the same weak password everywhere. I still believe that.
|
||||
|
||||
[Bitwarden][8] has really matured since the last time I checked it out. Like LastPass, it is user-friendly, supports two-factor authentication, and is reasonably secure. Unlike LastPass, it is [open source][9]. It can be used with or without the browser plugin and supports importing from other solutions including LastPass. The core functionality is completely free, and there is a premium version that is $10/year.
|
||||
|
||||
### Vimium-FF
|
||||
|
||||
![Vimium][10]
|
||||
|
||||
[Vimium][11] is another open source extension that provides Firefox keyboard shortcuts for navigation and control in the spirit of Vim. They call it "The Hacker's Browser." Modifier keys are specified as **< c-x>**, **< m-x>**, and **< a-x>** for Ctrl+x, Meta+x, and Alt+x, respectively, and the defaults can be easily customized. Once you have Vimium installed, you can see this list of key bindings at any time by typing **?**. Note that if you prefer Emacs, there are also a couple of extensions for those keybindings as well. Either way, I think keyboard shortcuts are an underutilized productivity booster.
|
||||
|
||||
### Bonus: Grammarly
|
||||
|
||||
Not everyone is lucky enough to write a column on Opensource.com—although you should seriously consider writing for the site; if you have questions, are interested, or would like a mentor, reach out and let's chat. But even without a column to write, proper grammar is beneficial in a large variety of situations. Enter [Grammarly][12]. This extension is not open source, unfortunately, but it does make sure everything you type is clear, effective, and mistake-free. It does this by scanning your text for common and complex grammatical mistakes, spanning everything from subject-verb agreement to article use to modifier placement. Basic functionality is free, with a premium version with additional checks available for a monthly charge. I used it for this article and it caught multiple errors that my proofreading didn't.
|
||||
|
||||
Again, Grammarly is the only extension included on this list that is not open source, so if you know of a similar high-quality open source replacement, let us know in the comments.
|
||||
|
||||
These extensions are ones I've found useful and recommend to others. Let me know in the comments what you think of the updated recommendations.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/5/firefox-extensions
|
||||
|
||||
作者:[Jeremy Garcia][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://opensource.com/users/jeremy-garcia
|
||||
[1]:https://opensource.com/article/18/1/top-5-firefox-extensions
|
||||
[2]:https://opensource.com/sites/default/files/styles/panopoly_image_original/public/ublock.png?itok=_QFEbDmq (ublock origin ad blocker screenshot)
|
||||
[3]:https://addons.mozilla.org/en-US/firefox/addon/ublock-origin/
|
||||
[4]:https://opensource.com/sites/default/files/styles/panopoly_image_original/public/images/life-uploads/privacy_badger_1.0.1.png?itok=qZXQeKtc (privacy badger ad blocker screenshot)
|
||||
[5]:https://www.eff.org/privacybadger
|
||||
[6]:https://www.eff.org/https-everywhere
|
||||
[7]:https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/bitwarden.png?itok=gZPrCYoi (Bitwarden)
|
||||
[8]:https://bitwarden.com/
|
||||
[9]:https://github.com/bitwarden
|
||||
[10]:https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/vimium.png?itok=QRESXjWG (Vimium)
|
||||
[11]:https://addons.mozilla.org/en-US/firefox/addon/vimium-ff/
|
||||
[12]:https://www.grammarly.com/
|
@ -1,3 +1,4 @@
|
||||
translating by wyxplus
|
||||
How to Install and Configure KVM on Ubuntu 18.04 LTS Server
|
||||
======
|
||||
**KVM** (Kernel-based Virtual Machine) is an open source full virtualization solution for Linux like systems, KVM provides virtualization functionality using the virtualization extensions like **Intel VT** or **AMD-V**. Whenever we install KVM on any linux box then it turns it into the hyervisor by loading the kernel modules like **kvm-intel.ko** ( for intel based machines) and **kvm-amd.ko** ( for amd based machines).
|
||||
|
@ -0,0 +1,119 @@
|
||||
DevOps时代的7个领导准则
|
||||
======
|
||||
|
||||

|
||||
|
||||
如果[DevOps]最终更多的是关于文化而不是任何其他的技术或者平台,那么请记住:没有终点线。而是继续改变和提高--而且最高管理层并没有通过。
|
||||
|
||||
然而,如果期望DevOps能够帮助获得更多的成果,领导者需要[修订他们的一些传统的方法][2]让我们考虑7个在DevOps时代更有效的IT领导的想法。
|
||||
|
||||
### 1. 向失败说“是的”
|
||||
|
||||
“失败”这个词在IT领域中一直包含着特殊的内涵,而且通常是糟糕的意思:服务器失败,备份失败,硬盘驱动器失败-你得了解这些情况。
|
||||
|
||||
然而一种健康的DevOps文化取决于重新定义失败-IT领导者在他们的字典里应该重新定义这个单词将它的含义和“机会”对等起来。
|
||||
|
||||
“在DevOps之前,我们曾有一种惩罚失败者的文化,”罗伯特·里夫斯说,[Datical][3]的首席技术官兼联合创始人。“我们学到的仅仅是去避免错误。在IT领域避免错误的首要措施就是不要去改变任何东西:不要加速版本迭代的日程,不要迁移到云中,不要去做任何不同的事”
|
||||
|
||||
那是过去的一个时代的剧本,里夫斯坦诚的说,它已经不起作用了,事实上,那种停滞是失败的。
|
||||
|
||||
“那些缓慢的释放并逃避云的公司被恐惧所麻痹-他们将会走向失败,”里夫斯说道。“IT领导者必须拥抱失败并把它当做成一个机遇。人们不仅仅从他们的过错中学习,也会从其他的错误中学习。一种开放和[安全心里][4]的文化促进学习和提高”
|
||||
**[相关文章:[为什么敏捷领导者谈论“失败”必须超越它本义]]
|
||||
### 2. 在管理层渗透开发运营的理念
|
||||
|
||||
尽管DevOps文化可以在各个方向有机的发展,那些正在从整体中转变,孤立的IT实践,而且可能遭遇逆风的公司-需要执行领导层的全面支持。你正在传达模糊的信息
|
||||
而且可能会鼓励那些愿意推一把的人,这是我们一贯的做事方式。[改变文化是困难的][6];人们需要看到领导层完全投入进去并且知道改变已经实际发生了。
|
||||
|
||||
“为了成功的实现利益的兑现高层管理必须全力支持DevOps,”来自[Rainforest QA][7]的首席技术官说道。
|
||||
|
||||
成为一个DevOps商店。德里克指出,涉及到公司的一切,从技术团队到工具到进程到规则和责任。
|
||||
|
||||
"没有高层管理的统一赞助支持,DevOps的实施将很难成功,"德里克说道。"因此,在转变到DevOps之前在高层中有支持的领导同盟是很重要的。"
|
||||
|
||||
### 3. 不要只是声明“DevOps”-要明确它
|
||||
即使IT公司也已经开始拥抱欢迎DevOps,每个人可能不是在同一个进程上。
|
||||
**[参考我们的相关文章,**][**3 阐明了DevOps和首席技术官们必须在同一进程上**][8] **.]**
|
||||
|
||||
造成这种脱节的一个根本原因是:人们对这个术语的有着不同的定义理解。
|
||||
|
||||
“DevOps 对不同的人可能意味着不同的含义,”德里克解释道。“对高管层和副总裁层来说,执行明确的DevOps的目标,清楚的声明期望的成果,充分理解带来的成果将如何使公司的商业受益并且能够衡量和报告成功的过程。”
|
||||
|
||||
事实上,在基线和视野之上,DevOps要求正在进行频繁的交流,不是仅仅在小团队里,而是要贯穿到整个组织。IT领导者必须为它设置优先级。
|
||||
|
||||
“不可避免的,将会有些阻碍,在商业中将会存在失败和破坏,”德里克说道。“领导者名需要清楚的将这个过程向公司的其他人阐述清楚告诉他们他们作为这个过程的一份子能够期待的结果。”
|
||||
|
||||
### 4. DevOps和技术同样重要
|
||||
|
||||
IT领导者们成功的将DevOps商店的这种文化和实践当做一项商业策略,与构建和运营软件的方法相结合。DevOps是将IT从支持部门转向战略部门的推动力。
|
||||
|
||||
IT领导者们必须转变他们的思想和方法,从成本和服务中心转变到驱动商业成果,而且DevOps的文化能够通过自动化和强大的协作加速收益。来自[CYBRIC][9]的首席技术官和联合创始人迈克说道。
|
||||
|
||||
事实上,这是一个强烈的趋势通过更多的这些规则在DevOps时代走在前沿。
|
||||
|
||||
“促进创新并且鼓励团队成员去聪明的冒险是DevOps文化的一个关键部分,IT领导者们需要在一个持续的基础上清楚的和他们交流,”凯尔说道。
|
||||
|
||||
“一个高效的IT领导者需要比以往任何时候都要积极的参与到商业中去,”来自[West Monroe Partners][10]的性能服务部门的主任埃文说道。“每年或季度回顾的日子一去不复返了-你需要欢迎每两周一次的待办事项。[11]你需要有在年度水平上的思考战略能力,在冲刺阶段的互动能力,在商业期望满足时将会被给予一定的奖励。”
|
||||
|
||||
### 5. 改变妨碍DevOps目标的任何事情
|
||||
|
||||
虽然DevOps的老兵们普遍认为DevOps更多的是一种文化而不是技术,成功取决于通过正确的过程和工具激活文化。当你声称自己的部门是一个DevOps商店却拒绝对进程或技术做必要的改变,这就是你买了辆法拉利却使用了用过20年的引擎,每次转动钥匙都会冒烟。
|
||||
|
||||
展览 A: [自动化][12].这是DevOps成功的重要并行策略。
|
||||
|
||||
“IT领导者需要重点强调自动化,”卡伦德说。“这将是DevOps的前期投资,但是如果没有它,DevOps将会很容易被低效吞噬自己而且将会无法完整交付。”
|
||||
|
||||
自动化是基石,但改变不止于此。
|
||||
|
||||
“领导者们需要推动自动化,监控和持续的交付过程。这意着对现有的实践,过程,团队架构以及规则的很多改变,”Choy说。“领导者们需要改变一切会阻碍隐藏团队去全利实现自动化的因素。”
|
||||
|
||||
### 6. 重新思考团队架构和能力指标
|
||||
|
||||
当你想改变时...如果你桌面上的组织结构图和你过去大部分时候嵌入的名字都是一样的,那么你是时候该考虑改革了。
|
||||
|
||||
“在这个DevOps的新时代文化中,IT执行者需要采取一个全新的方法来组织架构。”Kail说。“消除组织的边界限制,它会阻碍团队间的合作,允许团队自我组织,敏捷管理。”
|
||||
|
||||
Kail告诉我们在DevOps时代,这种反思也应该拓展应用到其他领域,包括你怎样衡量个人或者团队的成功,甚至是你和人们的互动。
|
||||
|
||||
“根据业务成果和总体的积极影响来衡量主动性,”Kail建议。“最后,我认为管理中最重要的一个方面是:有同理心。”
|
||||
|
||||
注意很容易收集的到测量值不是DevOps真正的指标,[Red Hat]的技术专员Gardon Half写到,“DevOps应该把指标以某种形式和商业成果绑定在一起,”他指出。“你可能真的不在乎开发者些了多少代码,是否有一台服务器在深夜硬件损坏,或者是你的测试是多么的全面。你甚至都不直接关注你的网站的响应情况或者是你更新的速度。但是你要注意的是这些指标可能和顾客放弃购物车去竞争对手那里有关,”参考他的文章,[DevOps 指标:你在测量什么?]
|
||||
|
||||
### 7. 丢弃传统的智慧
|
||||
|
||||
如果DevOps时代要求关于IT领导能力的新的思考方式,那么也就意味着一些旧的方法要被淘汰。但是是哪些呢?
|
||||
|
||||
“是实话,是全部,”Kail说道。“要摆脱‘因为我们一直都是以这种方法做事的’的心态。过渡到DevOps文化是一种彻底的思维模式的转变,不是对瀑布式的过去和变革委员会的一些细微改变。”
|
||||
|
||||
事实上,IT领导者们认识到真正的变革要求的不只是对旧方法的小小接触。它更多的是要求对之前的进程或者策略的一个重新启动。
|
||||
|
||||
West Monroe Partners的卡伦德分享了一个阻碍DevOps的领导力的例子:未能拥抱IT混合模型和现代的基础架构比如说容器和微服务
|
||||
|
||||
“我所看到的一个大的规则就是架构整合,或者认为在一个同质的环境下长期的维护会更便宜,”卡伦德说。
|
||||
|
||||
**想要更多像这样的智慧吗?[注册我们的每周邮件新闻报道][15].**
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://enterprisersproject.com/article/2018/1/7-leadership-rules-devops-age
|
||||
|
||||
作者:[Kevin Casey][a]
|
||||
译者:[译者FelixYFZ](https://github.com/FelixYFZ)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://enterprisersproject.com/user/kevin-casey
|
||||
[1]:https://enterprisersproject.com/tags/devops
|
||||
[2]:https://enterprisersproject.com/article/2017/7/devops-requires-dumping-old-it-leadership-ideas
|
||||
[3]:https://www.datical.com/
|
||||
[4]:https://rework.withgoogle.com/guides/understanding-team-effectiveness/steps/foster-psychological-safety/
|
||||
[5]:https://enterprisersproject.com/article/2017/10/why-agile-leaders-must-move-beyond-talking-about-failure?sc_cid=70160000000h0aXAAQ
|
||||
[6]:https://enterprisersproject.com/article/2017/10/how-beat-fear-and-loathing-it-change
|
||||
[7]:https://www.rainforestqa.com/
|
||||
[8]:https://enterprisersproject.com/article/2018/1/3-areas-where-devops-and-cios-must-get-same-page
|
||||
[9]:https://www.cybric.io/
|
||||
[10]:http://www.westmonroepartners.com/
|
||||
[11]:https://www.scrumalliance.org/community/articles/2017/february/product-backlog-grooming
|
||||
[12]:https://www.redhat.com/en/topics/automation?intcmp=701f2000000tjyaAAA
|
||||
[13]:https://www.redhat.com/en?intcmp=701f2000000tjyaAAA
|
||||
[14]:https://enterprisersproject.com/article/2017/7/devops-metrics-are-you-measuring-what-matters
|
||||
[15]:https://enterprisersproject.com/email-newsletter?intcmp=701f2000000tsjPAAQ
|
@ -0,0 +1,166 @@
|
||||
你应该知道关于 Ubuntu 18.04 的一些事
|
||||
======
|
||||
|
||||
[Ubuntu 18.04 版本][1] 即将到来。我可以在各种 Facebook 群组和论坛中看到许多来自 Ubuntu 用户的提问。我还在 Facebook 和 Instagram 上组织了 Q&A 会议,以了解 Ubuntu 用户对 Ubuntu 18.04 的想法。
|
||||
|
||||
我试图在这里回答关于 Ubuntu 18.04 的常见问题。如果您有任何疑问,我希望这能帮助您解决疑问。如果您仍有问题,请随时在下面的评论区提问。
|
||||
|
||||
### Ubuntu 18.04 中有什么值得期待
|
||||
|
||||
![Ubuntu 18.04 Frequently Asked Questions][2]
|
||||
|
||||
解释一下,这里的一些问答会受到我个人的影响。如果您是一位经验丰富或了解 Ubuntu 的用户,其中一些问题可能对您而言很简单。如果是这样的话,就请忽略这些问题。
|
||||
|
||||
#### 我能够在 Ubuntu 18.04 中安装 Unity 吗?
|
||||
|
||||
当然能够哦!
|
||||
|
||||
Canonical 公司知道有些人喜欢 Unity。这就是为什么它已经在 Universe 软件库(LCTT译者注:社区维护的软件库)中提供了 Unity 7。但这是一个社区维护版,官方并不直接参与开发。
|
||||
|
||||
但我建议是使用默认的 GNOME,除非您真的无法容忍它,再在 [Ubuntu 18.04 上安装 Unity][3]。
|
||||
|
||||
#### GNOME 是什么版本?
|
||||
|
||||
在这次发行的 Ubuntu 18.04 版本中,GNOME 版本号是 3.28。
|
||||
|
||||
#### 我能够安装 vanilla GNOME?
|
||||
|
||||
当然没问题!
|
||||
|
||||
因为存在一些 GNOME 用户可能不喜欢 Ubuntu 18.04 中的 Unity 风格。在 Ubuntu 中的 main(LCTT译者注:官方支持的软件库)和 universe 软件库有安装包可安装,能使您在 [Ubuntu 18.04 中安装 vanilla GNOME][4]。
|
||||
|
||||
#### GNOME中的内存泄漏已修复了吗?
|
||||
|
||||
已经修复了。[GNOME 3.28 中臭名昭着的内存泄漏][5] 已经被修复了,并且 [Ubuntu 官方已经在测试这个修复程序][6]。
|
||||
|
||||
澄清一点,内存泄漏不是由 Ubuntu 系统引起的。它影响了所有使用 GNOME 3.28 的 Linux 发行版。GNOME 3.28.1 发布了一个新的补丁修复内存泄漏问题。
|
||||
|
||||
#### Ubuntu 18.04 将会被支持多久?
|
||||
|
||||
这是一个长期支持(LTS)版本,与任何 LTS 版本一样,官方会支持五年。这意味着 Ubuntu 18.04 将在 2023 年 4 月之前能获得安全和维护更新。这对于除 Ubuntu Studio 之外的所有基于 Ubuntu 的 Linux 发行版也一样。
|
||||
|
||||
#### Ubuntu 18.04 什么时候会发布?
|
||||
|
||||
Ubuntu 18.04 LTS 在 4 月 26 日发布。 所有基于 Ubuntu 的 Linux 发行版,如 Kubuntu,Lubuntu,Xubuntu,Budgie,MATE 等都会在同一天发布其 18.04 版本。
|
||||
|
||||
不过 [Ubuntu Studio 不会有 18.04 的 LTS 版本][7]。
|
||||
|
||||
#### 是否能从16.04/17.10升级到 Ubuntu 18.04?我可以从使用 Unity 的 Ubuntu 16.04 升级到使用 GNOME 的 Ubuntu 18.04 吗?
|
||||
|
||||
绝对没问题。当 Ubuntu 18.04 LTS 发布后,您可以很容易的升级到最新版。
|
||||
|
||||
如果您使用的是 Ubuntu 17.10,请确保在软件和更新->更新中,将“有新版本时通知我”设置为“适用任何新版本”。
|
||||
|
||||
|
||||
![Get notified for a new version in Ubuntu][8]
|
||||
|
||||
如果您使用的是 Ubuntu 16.04,请确保在软件和更新->更新中,将“有新版本时通知我”设置为“适用长期支持版本”。
|
||||
|
||||
|
||||
![Ubuntu 18.04 upgrade from Ubuntu 16.04][9]
|
||||
|
||||
然后您应该能获得有关新版本更新的系统通知。之后,升级到 Ubuntu 18.04 只需要点击几下鼠标而已。
|
||||
|
||||
即使 Ubuntu 16.04 使用的是 Unity,但您仍然可以 [升级到使用 GNOME 的 Ubuntu 18.04][10]。
|
||||
|
||||
|
||||
#### 升级到 Ubuntu 18.04 意味着什么?我会丢失数据吗?
|
||||
|
||||
|
||||
如果您使用的是 Ubuntu 17.10 或 Ubuntu 16.04,系统会提示您可升级到 Ubuntu 18.04。如果您从互联网上下载 1.5 Gb 的数据不成问题,则只需点击几下鼠标,即可在 30 分钟内升级到 Ubuntu 18.04。
|
||||
|
||||
您不需要通过 U 盘来重装系统。升级过程完成后,您将可以使用新的 Ubuntu 版本。
|
||||
|
||||
通常,您的数据和文档等在升级过程中是安全的。但是,对重要文档进行备份始终是一个好的习惯。
|
||||
|
||||
#### 我什么时候能升级到 Ubuntu 18.04?
|
||||
|
||||
如果您使用的是 Ubuntu 17.10 并且正确设置(设置方法在之前提到的问题中),那么在 Ubuntu 18.04 发布的几天内应该会通知您升级到 Ubuntu 18.04。为避免 Ubuntu 服务器在发布日期负载量过大,因此不是每个人都会在同一天收到升级提示。
|
||||
|
||||
对于 Ubuntu 16.04 用户,可能需要几周时间才能正式收到 Ubuntu 18.04 升级提示。通常,这将在第一次发布 Ubuntu 18.04.1 之后提示。该版本修复了 18.04 中发现的新 bug。
|
||||
|
||||
#### 如果我升级到 Ubuntu 18.04,我可以降级到 17.10/16.04?
|
||||
|
||||
抱歉,并不行。尽管升级到新版本很容易,但没有降级的选项。如果您想回到 Ubuntu 16.04,只能重新安装。
|
||||
|
||||
#### 我能使用 Ubuntu 18.04 在 32 位系统上吗?
|
||||
|
||||
可以,但最好不要这样做。
|
||||
|
||||
如果您已经在使用 32 位版本的 Ubuntu 16.04 或 17.10,您依旧可以升级到 Ubuntu 18.04。 但是,您找到不到 32 位的 Ubuntu 18.04 ISO 镜像。换句话说,您无法安装 32 位版本的 Ubuntu 18.04。
|
||||
|
||||
|
||||
有一个好消息是,Ubuntu MATE,Lubuntu 等其他官方版本仍然具有其新版本的 32 位 ISO 镜像。
|
||||
|
||||
无论如何,如果您使用一个 32 位系统,那么很可能您的计算机硬件性能过低。在这样的电脑上使用轻量级 [Ubuntu MATE][11] 或 [Lubuntu][12] 系统会更好。
|
||||
|
||||
|
||||
#### 我可以在哪下载 Ubuntu 18.04?
|
||||
|
||||
一旦发布了 18.04,您可以从其网站获得 Ubuntu 18.04 的 ISO 镜像。您既可以直接官网下载,也能用种子下载。其他官方版本将在其官方网站上提供下载。
|
||||
|
||||
|
||||
#### 我应该重新安装 Ubuntu 18.04 还是从 16.04/17.10 升级上来?
|
||||
|
||||
如果您有重新安装的机会,建议备份您的数据并重新安装 Ubuntu 18.04。
|
||||
|
||||
从现有版本升级到 18.04 是一个方便的选择。不过,就我个人而言,它仍然保留了旧版本的依赖包。重新安装还是比较干净。
|
||||
|
||||
对于重新安装来说,我应该安装 Ubuntu 16.04 还是 Ubuntu 18.04?
|
||||
|
||||
如果您要在计算机上安装 Ubuntu,请尽量使用 Ubuntu 18.04 而不是 16.04。
|
||||
|
||||
他们都是长期支持版本,并被支持很长一段时间。Ubuntu 16.04 会获得维护和安全更新服务直到 2021 年,而 18.04 则会到 2023 年。
|
||||
|
||||
不过,我建议您使用 Ubuntu 18.04。任何 LTS 版本都会在 [一段时间内获得硬件更新支持][13](我认为是两年半的时间内)。之后,它只获得维护更新。如果您有更新的硬件,您将在 18.04 获得更好的支持。
|
||||
|
||||
此外,许多应用程序开发人员将很快开始关注 Ubuntu 18.04。新创建的 PPA 可能仅在几个月内支持 18.04。所以使用 18.04 比 16.04 更好。
|
||||
|
||||
|
||||
#### 安装打印机-扫描仪驱动程序比使用 CLI 安装会更容易吗?
|
||||
|
||||
在打印机方面,我不是专家,所以我的观点是基于我在这方面有限的知识。大多数新打印机都支持 [IPP协议][14],因此它们应该在 Ubuntu 18.04 中能够获到很好的支持。 然而对较旧的打印机我则无法保证。
|
||||
|
||||
#### Ubuntu 18.04 是否对 Realtek 和其他 WiFi 适配器有更好的支持?
|
||||
|
||||
抱歉,没有关于这部分的具体信息。
|
||||
|
||||
#### Ubuntu 18.04 的系统要求?
|
||||
|
||||
|
||||
对于默认的 GNOME 版本,最好您应该有 [4 GB 的内存以便正常使用][15]。使用过去 8 年中发布的处理器也可以运行。但任何比这性能更差的硬件建议使用 [轻量级 Linux 发行版][16],例如 [Lubuntu][12]。
|
||||
|
||||
|
||||
|
||||
#### 有关 Ubuntu 18.04 的其问题?
|
||||
|
||||
如果还有其他疑问,请随时在下方评论区留言。如果您认为应将其他信息添加到列表中,请告诉我。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/ubuntu-18-04-faq/
|
||||
|
||||
作者:[Abhishek Prakash][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[wyxplus](https://github.com/wyxplus)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://itsfoss.com/author/abhishek/
|
||||
[1]:https://itsfoss.com/ubuntu-18-04-release-features/
|
||||
[2]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/04/ubuntu-18-04-faq-800x450.png
|
||||
[3]:https://itsfoss.com/use-unity-ubuntu-17-10/
|
||||
[4]:https://itsfoss.com/vanilla-gnome-ubuntu/
|
||||
[5]:https://feaneron.com/2018/04/20/the-infamous-gnome-shell-memory-leak/
|
||||
[6]:https://community.ubuntu.com/t/help-test-memory-leak-fixes-in-18-04-lts/5251
|
||||
[7]:https://www.omgubuntu.co.uk/2018/04/ubuntu-studio-plans-to-reboot
|
||||
[8]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/03/upgrade-ubuntu-2.jpeg
|
||||
[9]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2017/10/ubuntu-18-04-upgrade-settings-800x379.png
|
||||
[10]:https://itsfoss.com/upgrade-ubuntu-version/
|
||||
[11]:https://ubuntu-mate.org/
|
||||
[12]:https://lubuntu.net/
|
||||
[13]:https://www.ubuntu.com/info/release-end-of-life
|
||||
[14]:https://www.pwg.org/ipp/everywhere.html
|
||||
[15]:https://help.ubuntu.com/community/Installation/SystemRequirements
|
||||
[16]:https://itsfoss.com/lightweight-linux-beginners/
|
@ -0,0 +1,77 @@
|
||||
4 个 Firefox 扩展
|
||||
=====
|
||||
|
||||

|
||||
正如我在关于 Firefox 扩展的[原创文章][1]中提到的,web 浏览器已成为许多用户计算(机)验的关键组件。现代浏览器已经发展成为功能强大且可扩展的平台,扩展可以添加或修改其功能。Firefox 的扩展是使用 WebExtensions API(一种跨浏览器开发系统)构建的。
|
||||
|
||||
在第一篇文章中,我问读者:“你应该安装哪些扩展?” 重申一下,这一决定主要取决于你如何使用浏览器,你对隐私的看法,你对扩展程序开发人员的信任程度以及其他个人偏好。自文章发表以来,我推荐的一个扩展(Xmarks)已经停止。另外,该文章收到了大量的反馈,在这篇更新中,这些反馈已经被考虑到。
|
||||
|
||||
我想再次指出,浏览器扩展通常需要能够阅读和(或)更改你访问的网页上的所有内容。你应该仔细考虑这一点。如果扩展程序修改了你访问的所有网页的访问权限,那么它可能充当键盘记录程序,拦截信用卡信息,在线跟踪,插入广告以及执行各种其他恶意活动。这并不意味着每个扩展程序都会暗中执行这些操作,但在安装任何扩展程序之前,你应该仔细考虑安装源,涉及的权限,风险配置文件以及其他因素。请记住,你可以使用配置文件来管理扩展如何影响你的攻击面 - 例如,使用没有扩展的专用配置文件来 执行网上银行等任务。
|
||||
|
||||
考虑到这一点,这里有你可能想要考虑的四个开源 Firefox 扩展。
|
||||
|
||||
### uBlock Origin
|
||||
|
||||
![ublock origin ad blocker screenshot][2]
|
||||
|
||||
我的第一个建议保持不变。[uBlock Origin][3] 是一款快速,低内存,广泛的拦截器,它不仅可以拦截广告,而且还可以执行你自己的内容过滤。 uBlock Origin 的默认行为是使用多个预定义的过滤器列表来拦截广告,跟踪器和恶意软件站点。它允许你任意添加列表和规则,甚至可以锁定到默认拒绝模式。尽管它很强大,但它已被证明是高效和高性能的。它将继续定期更新,并且是该功能的最佳选择之一。
|
||||
|
||||
### Privacy Badger
|
||||
|
||||
![privacy badger ad blocker][4]
|
||||
|
||||
我的第二个建议也保持不变。如果说有什么区别的话,那就是自从我上一篇文章发表以来,隐私问题就一直被带到最前沿,这使得这个扩展成为一个简单的建议。顾名思义,[Privacy Badger][5] 是一个专注于隐私的扩展,可以拦截广告和其他第三方跟踪器。这是 Electronic Freedom (to 校正者:这里 Firefox 添加此扩展后,弹出页面译为电子前哨基金会)基金会的一个项目,他们说:
|
||||
|
||||
> Privacy Badger 诞生于我们希望能够推荐一个单独的扩展,它可以自动分析和拦截任何违反用户同意原则的追踪器或广告;在用户没有任何设置、有关知识或配置的情况下,它可以很好地运行;它是由一个明确为其用户而不是为广告商工作的组织所产生的;它使用了算法的方法来决定什么是什么,什么是不跟踪的。”
|
||||
|
||||
为什么 Privacy Badger 会出现在这个列表上,它的功能与上一个扩展看起来很类似?因为一些原因。首先,它从根本上工作原理与 uBlock Origin 不同。其次,深度防御的实践是一项合理的策略。说到深度防御,EFF 还维护着 [HTTPS Everywhere][6] 扩展,它自动确保 https 用于许多主流网站。当你安装 Privacy Badger 时,你也可以考虑使用 HTTPS Everywhere。
|
||||
|
||||
如果你开始认为这篇文章只是对上一篇文章的重新讨论,那么以下是我的建议分歧。
|
||||
|
||||
### Bitwarden
|
||||
|
||||
![Bitwarden][7]
|
||||
|
||||
在上一篇文章中推荐 LastPass 时,我提到这可能是一个有争议的选择。这无疑属实。无论你是否应该使用密码管理器 - 如果你使用,那么是否应该选择带有浏览器插件的密码管理器 - 这是一个备受争议的话题,答案很大程度上取决于你的个人风险状况。我认为大多数普通的计算机用户应该使用一个,因为它比最常见的选择要好得多:在任何地方都使用相同的弱密码。我仍然相信这一点。
|
||||
|
||||
[Bitwarden][8] 自从我上次审视以后确实成熟了。像 LastPass 一样,它对用户友好,支持双因素身份验证,并且相当安全。与 LastPass 不同的是,它是[开源的][9]。它可以使用或不使用浏览器插件,并支持从其他解决方案(包括 LastPass)导入。它的核心功能完全免费,它还有一个 10 美元/年的高级版本。
|
||||
|
||||
### Vimium-FF
|
||||
|
||||
![Vimium][10]
|
||||
|
||||
[Vimium][11] 是另一个开源的扩展,它为 Firefox 键盘快捷键提供了类似 Vim 一样的导航和控制,其称之为“黑客的浏览器”。对于 Ctrl+x, Meta+x 和 Alt+x,分别对应 **< c-x>**, **< m-x>** 和 **< a-x>**,默认值可以轻松定制。一旦你安装了 Vimium,你可以随时键入 **?** 来查看键盘绑定列表。请注意,如果你更喜欢 Emacs,那么也有一些针对这些键绑定的扩展。无论哪种方式,我认为键盘快捷键是未充分利用的生产力推动力。
|
||||
|
||||
### 额外福利: Grammarly
|
||||
|
||||
不是每个人都有幸在 Opensource.com 上撰写专栏 - 尽管你应该认真考虑为网站撰写文章;如果你有问题,有兴趣,或者想要一个导师,伸出手,让我们聊天吧。但是,即使没有专栏撰写,正确的语法在各种各样的情况下都是有益的。试一下 [Grammarly][12]。不幸的是,这个扩展不是开源的,但它确实可以确保你输入的所有东西都是清晰的,有效的并且没有错误。它通过扫描你文本中的常见的和复杂的语法错误来实现这一点,涵盖了从主谓一致到文章使用到修饰词的放置这些所有内容。它的基本功能是免费的,它有一个高级版本,每月收取额外的费用。我在这篇文章中使用了它,它发现了许多我的校对没有发现的错误。
|
||||
|
||||
再次说明,Grammarly 是这个列表中包含的唯一不是开源的扩展,因此如果你知道类似的高质量开源替代品,请在评论中告诉我们。
|
||||
|
||||
这些扩展是我发现有用并推荐给其他人的扩展。请在评论中告诉我你对更新建议的看法。
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/5/firefox-extensions
|
||||
|
||||
作者:[Jeremy Garcia][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[MjSeven](https://github.com/MjSeven)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://opensource.com/users/jeremy-garcia
|
||||
[1]:https://opensource.com/article/18/1/top-5-firefox-extensions
|
||||
[2]:https://opensource.com/sites/default/files/styles/panopoly_image_original/public/ublock.png?itok=_QFEbDmq (ublock origin ad blocker screenshot)
|
||||
[3]:https://addons.mozilla.org/en-US/firefox/addon/ublock-origin/
|
||||
[4]:https://opensource.com/sites/default/files/styles/panopoly_image_original/public/images/life-uploads/privacy_badger_1.0.1.png?itok=qZXQeKtc (privacy badger ad blocker screenshot)
|
||||
[5]:https://www.eff.org/privacybadger
|
||||
[6]:https://www.eff.org/https-everywhere
|
||||
[7]:https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/bitwarden.png?itok=gZPrCYoi (Bitwarden)
|
||||
[8]:https://bitwarden.com/
|
||||
[9]:https://github.com/bitwarden
|
||||
[10]:https://opensource.com/sites/default/files/styles/panopoly_image_original/public/u128651/vimium.png?itok=QRESXjWG (Vimium)
|
||||
[11]:https://addons.mozilla.org/en-US/firefox/addon/vimium-ff/
|
||||
[12]:https://www.grammarly.com/
|
Loading…
Reference in New Issue
Block a user