uanme -a
简单粗暴明了
下面这些命令,没有的话,需要自己重新安装,不大,占不了多少内存。
lspci
lsusb
lshw
lscpu
lshw
/proc
简单介绍工具lshw:
sudo lshw -html > lshw.html
这样就生成了.html,用浏览器打开就行了。
is a set of standards for physically connecting and transferring data between computer and peripheral devices.SCSI is most commonly used for hard disks and tape drives,but it can connect a wide range of other devices including scanners and CD drives.
ATA is short for AT COMPUTER attachment,means AT computer s attachment.You can easilly use ATA to connect harddisk on PC.
ATA is commonly consist of PATA(parallel ATA ) and SATA(serial ATA).
为了编译自己的内核,需要弄清楚各自的驱动。
为了知道自己的机器的具体硬件信息,请参考这篇文章:
迭代 查找单词collections.Counter()
for line in open('5.py'):
print(line.upper(), end='')
将5.py的每一行换成大写。
f = open('5.py')
while True:
line = f.readline()
if not line: break
print(line.upper(), end = ' ')
在交互模式下:
L = [1,2,3]
I = iter(L)
I.next()
请参阅这篇文章 here
for的使用主要注意, 后面的冒号。
在字典中的使用 :
#!/usr/bin/python
from __future__ import print_function
D = { 'a':1, 'b':2,'c':3}
for key in D:
print(key, '=>', D[key])
结果:
a => 1
c => 3
b => 2
关键注意字典的键和值。这一点在perl中也是很重要的。字典本身具有很多属性,稍微看一个。将上面的字典用items()打印出来就是
L = D.items()
print(L)
这是python 2.x中的用法,3.x直接调用: list(D.items())
for(key, value) in D.items():
print(key, '=>', value)
与上面实现了同样的方法。
这里的计数器类似于c语言中的for循环,典型的用法如下, from 0 to (i - 1):
for i in range(3):
print(i, 'pythons')
就会打印三个pythons.
处理字符串时利用 len()函数即可达到相同的作用。
X = 'spam'
for item in X:
print(item, end = ' ')
# 这两种循环都是一个作用。
i = 0
while i < len(X):
print(X[i], end = ' ')
i += 1
以上这两中并不是处理这类循环最佳的选择,下面的语句就可以简单的解决。
for item in X: print(x, end = ' ')
以下两种方法实现相同的功能:
S = 'abcdefghijk'
for i in range(0, len(S), 2): print(S[i], end = ' ')
print('\n')
# 使用切片技术
for c in S[::2]: print(c, end = ' ')
print('\n')
L = [1,2,4,5,6]
for i in range(len(L)):
L[i] += 1
print(L)
L1 = [1,2,4,5,6]
L2 = [2,3,5,6,7]
M = zip(L1,L2)
print(M)
for (x, y) in M:
print(x,y, '--', x + y)
zip可以接受任何类型的对象,下面这个例子。
L1 = [1,2,4,5,6]
L2 = [2,3,5,6,7]
L3 = [3,4,6,7,8]
print(list(zip(L1,L2,L3)))
打印的结果为:
[(1, 2, 3), (2, 3, 4), (4, 5, 6), (5, 6, 7), (6, 7, 8)]
zip函数以最短的对象为准。 map以None补全不够的那一部分。
S1 = 'abc'
S2 = 'hechun'
print(zip(S1, S2))
print(map(None, S1,S2))
可惜,3.0以上不支持这个函数了。
keys = ['spam', 'eggs', 'toast']
vals = [1, 2, 3]
print(list(zip(keys, vals)))
处理的结果是如下图所示:
[('spam', 1), ('eggs', 2), ('toast', 3)]
这样,我们并没有形成字典,正确的还需要多处理一步:
keys = ['spam', 'eggs', 'toast']
vals = [1, 2, 3]
print(list(zip(keys, vals)))
D2 = { }
for (k, v) in zip(keys, vals): D2[k] = v
print(D2)
其输出的结果如下所示:
[('spam', 1), ('eggs', 2), ('toast', 3)]
{'toast': 3, 'eggs': 2, 'spam': 1}
在2.x以后,可以直接使用dict函数。
D3 = dict(zip(keys, vals))
print(D3)
在python中,字符串的比较应该多留意下,不能直接比较,可以转化为浮点型进行比较
>>> a = '1.2'
>>> b = '100.9'
>>> c = '2.4'
>>> alist = [a, b, c]
>>> alist.sort()
>>> print(alist)
['1.2', '100.9', '2.4']
So , you would better to do it :
>>> a='1.2'
>>> b='100.9'
>>> c='2.4'
>>> alist=[float(a), float(b), float(c)]
>>> alist.sort()
>>> print(alist)
[1.2, 2.4, 100.9]
这个错误经常出现在当应用程序进行一些非阻塞(non-blocking)操作(对文件或socket)的时候。例如,以 O_NONBLOCK的标志打开文件/socket/FIFO,如果你连续做read操作而没有数据可读。此时程序不会阻塞起来等待数据准备就绪返回,read函数会返回一个错误EAGAIN,提示你的应用程序现在没有数据可读请稍后再试。
出现这个错误是因为函数没有任何数据被传送此时发生了中断,
如果出现:
error: implicit declaration of function ‘kmalloc’ [-Werror=implicit-function-declaration]
你应该添加上 #include
下面这些操作与模块有关。
这个函数是打印出module的属性
除此之外集合实例也可以查看其自己的所有使用方法。
导入一个模块文件
这个集合与数学中的集合类似,可以进行相关的‘与’、‘或’、‘非’等操作
>>> x = set('abcde')
>>> y = set('bdxyz')
>>> x
set(['a', 'c', 'b', 'e', 'd'])
>>> 'e' in x
True
>>> x | y
set(['a', 'c', 'b', 'e', 'd', 'y', 'x', 'z'])
>>> x & y
set(['b', 'd'])
>>> z = x.intersection(y)
>>> z
set(['b', 'd'])
# 以上两种都是求交集
>>> x - y
set(['a', 'c', 'e'])
>>> x ^y
set(['a', 'c', 'e', 'y', 'x', 'z'])
使用其他方式改变集合的样子
# 求交集
>>> z = x.intersection(y)
>>> z
set(['b', 'd'])
# add 插入一个项目
>>> z.add('spam')
>>> z
set(['b', 'd', 'spam'])
# update按位置求并集
>>> z.update(set(['x','y']))
>>> z
set(['y', 'x', 'b', 'd', 'spam'])
# remove 删除一个项目
>>> z.remove('b')
>>> z
set(['y', 'x', 'd', 'spam'])
第二种方式成为集合的方法,前一种限制了两边必须是集合,后一种可以针对任何可迭代的对象
>>> s = set([1,2,3])
>>> s | set([3,4])
set([1, 2, 3, 4])
>>> s | [3,4]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for |: 'set' and 'list'
>>>
>>> s.union([3,4])
set([1, 2, 3, 4])
>>>
python3.0中以下形式是等价的:
set([1,2,3,4])
{1,2,3,4}
所谓的集合 解析就是将一个集合的每一个元素分离出来,在2.x中是下面这个样子的:
>>> {x ** 2 for x in [ 1,2,3,4]}
set([16, 1, 4, 9])
>>>
自己就生成了集合,在3.0中不会,直接就是{,,}的形式。
{ x for x in 'spam' }
set(['a', 'p', 's', 'm'])
>>>
x是循环变量在这个程序例子中。
>>> L = [1,2,3,4]
>>> set(L)
set([1, 2, 3, 4])
>>> L = list(set(L))
>>> L
[1, 2, 3, 4]
>>>
两种方法: int(N)和math.trunc(N)
>>> int(6.5)
6
>>> import math
>>> math.trunc(6.5)
6
两种方案: float(n)和混合运算
>>> float(6)
6.0
>>> 6 * 1.0
6.0
在2.x的情况下测试如下:
>>> hex(16)
'0x10'
>>> oct(765)
'01375'
>>> bin(16)
'0b10000'
使用int(S, base),其中base是进制的参数
>>> int('01375',8)
765
>>> int('0b10000',2)
16