# 我要偷偷的学Python，然后惊呆所有人（第四天）

## 前言

本系列文默认各位有一定的C或C++基础，因为我是学了点C++的皮毛之后入手的Python，这里也要感谢齐锋学长送来的支持。



## 什么是模块？

emmm，总觉得还是少了点什么，对，我们来扫描一个模块，瞟一眼就好啊，不求看懂，大概知道里面是啥，咱心里有点数：

from warnings import warn as _warn
from types import MethodType as _MethodType, BuiltinMethodType as _BuiltinMethodType
from math import log as _log, exp as _exp, pi as _pi, e as _e, ceil as _ceil
from math import sqrt as _sqrt, acos as _acos, cos as _cos, sin as _sin
from os import urandom as _urandom
from _collections_abc import Set as _Set, Sequence as _Sequence
from hashlib import sha512 as _sha512
import _random

__all__ = ["Random","seed","random","uniform","randint","choice","sample",
"randrange","shuffle","normalvariate","lognormvariate",
"expovariate","vonmisesvariate","gammavariate","triangular",
"gauss","betavariate","paretovariate","weibullvariate",
"getstate","setstate", "getrandbits",
"SystemRandom"]

NV_MAGICCONST = 4 * _exp(-0.5)/_sqrt(2.0)
TWOPI = 2.0*_pi
LOG4 = _log(4.0)
SG_MAGICCONST = 1.0 + _log(4.5)
BPF = 53        # Number of bits in a float
RECIP_BPF = 2**-BPF

class Random(_random.Random):
VERSION = 3     # used by getstate/setstate

def __init__(self, x=None):
self.seed(x)
self.gauss_next = None

def seed(self, a=None, version=2):
if a is None:
try:
# Seed with enough bytes to span the 19937 bit
# state space for the Mersenne Twister
a = int.from_bytes(_urandom(2500), 'big')
except NotImplementedError:
import time
a = int(time.time() * 256) # use fractional seconds

if version == 2:
if isinstance(a, (str, bytes, bytearray)):
if isinstance(a, str):
a = a.encode()
a += _sha512(a).digest()
a = int.from_bytes(a, 'big')

super().seed(a)
self.gauss_next = None
……


## 跟我一起动手导入自己的模块

### if __name__ == '__main__'

# 【文件：xx.py】

if __name__ == '__main__':
代码块 ②……


## csv模块操作Excel图表

Python手册（官方中文版）

### 使用csv模块

#### 读

import csv

with open('test.csv', newline = '', encoding = 'GBK')  as f:
#参数encoding = 'utf-8'防止出现乱码
print(row)


#### 写

import csv

with open('test.csv','a', newline='',encoding='utf-8') as f:
writer  = csv.writer(f)
writer.writerow(['6', '小黑', '65', '82', '86'])
writer.writerow(['7', '小红', '78', '64', '31'])


01-29 267
08-09 96
10-16 11万+
10-17 508
10-06 284
12-20 721