Free与python之禅

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Free与python之禅相关的知识,希望对你有一定的参考价值。

参考技术A 一条命令"free"显示内存的使用信息。 默认按照M的计数单位统计。

显示各个参数说明 :

              total表示 总计物理内存的大小。

              used表示 已使用多少。

              free表示 可用内存多少。

              Shared表示 多个进程共享的内存总额。

               Buffers/cached表示 磁盘缓存的大小。

第三行(-/+ buffers/cached)解释

               used:已使用多大。

                free:可用有多少。

第四行是交换分区SWAP的,也就是我们通常所说的虚拟内存。

我们按照系统应用程序来说:系统可用内存= 系统free+buffers+cached。

"free -g",按照g的计数方式来显示内存信息。

"free -m",按照M的计数方式来显示内存信息。

"free -k",按照K的计数方式来显示内存信息。

"free -t",按照总和的形式显示内存的使用信息。

"free -s 2 -c 4"。表示为周期性展示统计内存信息。本篇实例为每隔2秒统计一次,统计4次。

"free -s 5",表示周期性展示内存使用情况,意思为每隔5秒统计展示,直到我们按下ctrl +c 键取消统计为止。

查看版本信息,我们执行命令"free -V",进行查看

x86是一个intel 通用计算机 系列的标准编号缩写,也标识一套通用的 计算机指令 集合,X与处理器没有任何关系,它是一个对所有*86系统的简单的 通配符 定义,例如:i386, 586,奔腾(pentium)。

Intel从8086开始,286、386、486、586、P1、P2、P3、P4都用的同一种CPU架构,统称 X86 。

如果修改了当前文件,则写入当前文件并退出(与“:x”相同)。(注意:如果当前文件有多个窗口,如果文件被修改并且窗口被关闭,那么文件将被写入)。:另一方面,wq总是写文件并退出Vim。

《Python的禅宗》,蒂姆·彼得斯著

美丽胜过丑陋。

显性比隐性好。

简单胜于复杂。

复杂比复杂好。

平的比嵌套的好。

稀疏比稠密好。

可读性。

特殊情况并不足以打破规则。

尽管实用性比纯洁。

错误不应该悄无声息地过去。

除非显式地沉默。

面对模棱两可,拒绝猜测的诱惑。

应该有一种——最好只有一种——显而易见的方法。

尽管这种方式在一开始可能并不明显,除非你是荷兰人。

现在总比没有好。

虽然从来没有比现在更好过。

如果这个实现很难解释,那就是个坏主意。

如果实现很容易解释,这可能是个好主意。

名称空间是一个伟大的想法——让我们做更多的命名空间!

25Python之禅

要求:
爬取网页你好,蜘蛛侠!中的Python之禅中英文版本,并且打印。
 
目的:
练习使用selenium爬取动态网页的信息。
练习selenium与BeautifulSoup的搭配使用。
 
 
 
方法一: 用selenium
 
 1 from selenium import webdriver
 2 import time
 3 
 4 driver = webdriver.Chrome()
 5 
 6 driver.get(https://localprod.pandateacher.com/python-manuscript/hello-spiderman/)
 7 time.sleep(2)
 8 
 9 button = driver.find_element_by_class_name(sub)
10 button.click()
11 time.sleep(1)
12 
13 python_zens = driver.find_elements_by_class_name(content)
14 
15 for python_zen in python_zens:
16     print(python_zen.find_element_by_tag_name(h1).text,end=\\n\\n)
17     print(python_zen.find_element_by_tag_name(p).text,end=\\n\\n)
18 
19 driver.close()
 1 The Zen of Python
 2 
 3 Beautiful is better than ugly.
 4 Explicit is better than implicit.
 5 Simple is better than complex.
 6 Complex is better than complicated.
 7 Flat is better than nested.
 8 Sparse is better than dense.
 9 Readability counts.
10 Special cases arent special enough to break the rules.
11 Although practicality beats purity.
12 Errors should never pass silently.
13 Unless explicitly silenced.
14 In the face of ambiguity, refuse the temptation to guess.
15 There should be one-- and preferably only one --obvious way to do it.
16 Although that way may not be obvious at first unless youre Dutch.
17 Now is better than never.
18 Although never is often better than *right* now.
19 If the implementation is hard to explain, its a bad idea.
20 If the implementation is easy to explain, it may be a good idea.
21 Namespaces are one honking great idea -- lets do more of those!
22 
23 Python之禅
24 
25 优美胜于丑陋
26 明了胜于晦涩
27 简洁胜于复杂
28 复杂胜于凌乱
29 扁平胜于嵌套
30 间隔胜于紧凑
31 可读性很重要
32 即便假借特例的实用性之名,也不可违背这些规则
33 不要包容所有错误,除非你确定需要这样做
34 当存在多种可能,不要尝试去猜测
35 而是尽量找一种,最好是唯一一种明显的解决方案
36 虽然这并不容易,因为你不是 Python 之父
37 做也许好过不做,但不假思索就动手还不如不做
38 如果你无法向人描述你的方案,那肯定不是一个好方案;反之亦然
39 命名空间是一种绝妙的理念,我们应当多加利用
 
方法二:用selenium 和 BeautifulSoup
 
 1 from selenium import webdriver
 2 from bs4 import BeautifulSoup
 3 import time
 4 
 5 driver = webdriver.Chrome()
 6 
 7 driver.get(https://localprod.pandateacher.com/python-manuscript/hello-spiderman/)
 8 time.sleep(2)
 9 
10 button = driver.find_element_by_class_name(sub)
11 button.click()
12 time.sleep(1)
13 
14 pagesource = driver.page_source
15 
16 soup = BeautifulSoup(pagesource,html.parser)
17 items = soup.find_all(class_=content)
18 for item in items:
19     print(\\n\\t+item.find(h1).text)
20     print(item.find(p).text)
21 
22 driver.close()
 1         The Zen of Python
 2 
 3             Beautiful is better than ugly.
 4             Explicit is better than implicit.
 5             Simple is better than complex.
 6             Complex is better than complicated.
 7             Flat is better than nested.
 8             Sparse is better than dense.
 9             Readability counts.
10             Special cases arent special enough to break the rules.
11             Although practicality beats purity.
12             Errors should never pass silently.
13             Unless explicitly silenced.
14             In the face of ambiguity, refuse the temptation to guess.
15             There should be one-- and preferably only one --obvious way to do it.
16             Although that way may not be obvious at first unless youre Dutch.
17             Now is better than never.
18             Although never is often better than *right* now.
19             If the implementation is hard to explain, its a bad idea.
20             If the implementation is easy to explain, it may be a good idea.
21             Namespaces are one honking great idea -- lets do more of those!
22 
23         Python之禅
24 
25             优美胜于丑陋
26             明了胜于晦涩
27             简洁胜于复杂
28             复杂胜于凌乱
29             扁平胜于嵌套
30             间隔胜于紧凑
31             可读性很重要
32             即便假借特例的实用性之名,也不可违背这些规则
33             不要包容所有错误,除非你确定需要这样做
34             当存在多种可能,不要尝试去猜测
35             而是尽量找一种,最好是唯一一种明显的解决方案
36             虽然这并不容易,因为你不是 Python 之父
37             做也许好过不做,但不假思索就动手还不如不做
38             如果你无法向人描述你的方案,那肯定不是一个好方案;反之亦然
39             命名空间是一种绝妙的理念,我们应当多加利用

 技术图片

以上是关于Free与python之禅的主要内容,如果未能解决你的问题,请参考以下文章

25Python之禅

Python之禅,亦是人生之禅

Python基础(十四) | Python之禅与时间复杂度分析

Python之禅---1什么是编程语言

Python之禅

Python之禅