Python 常用模块总结

  • 1、random
  • 2、math
  • 3、os
  • 4、os.path
  • 5、sys
  • 6、hashlib
  • 7、hmac
  • 8、time
  • 9、datetime
  • 10、calendar
  • 11、UUID

常见的模块

  • random
  • math
  • datetime
  • time
  • os
  • os.path
  • sys
  • hashlib
  • hmac
    … …

模块的导入

>>> import os
>>> import hashlib [as hash]
>>> import http.server [as ser]
>>> from http import client [as cli]

1、random

作用:产生随机数

>>> import random
>>> dir(random)
['betavariate', 'choice', 'choices', 'expovariate', 'gammavariate', 'gauss', 'getrandbits', 'getstate', 'lognormvariate', 'normalvariate', 'paretovariate', 'randint', 'random', 'randrange', 'sample', 'seed', 'setstate', 'shuffle', 'triangular', 'uniform', 'vonmisesvariate', 'weibullvariate']
>>> random.randint(5, 10)      # 产生5--10之间的整数
8
>>> random.random()            # 产生0--1之间的整数
0.2718111326910797
>>> random.uniform(5, 10)      # 产生一个范围的正态分布的数
7.911538309334022
>>> ls = ['hello', 123, True, 4533]
>>> random.choice(ls)          # 在序列(seq)中随机筛选一个元素
'hello'

2、math

作用:用于数学计算

>>> import math
>>> dir(math)
['acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'comb', 'copysign', 'cos', 'cosh', 'degrees', 'dist', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'gcd', 'hypot', 'inf', 'isclose', 'isfinite', 'isinf', 'isnan', 'isqrt', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'log2', 'modf', 'nan', 'perm', 'pi', 'pow', 'prod', 'radians', 'remainder', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'tau', 'trunc']
>>> math.ceil(3.0000000001)   # 向上取整
4
>>> math.floor(3.0000000001)  # 向下取整
3
>>> math.fabs(-7)             # 求绝对值
7.0
>>> math.fmod(10, 3)          # 求模
1.0
>>> math.isnan(1)             # 判断一个数不是数字
False
>>> math.isfinite(5)          # 判断是否为数字(整数/浮点数,有限,无限或NaN),则返回True既不是无穷大也不是NaN(不是数字),否则返回False
True
>>> math.isfinite(math.e)
True
>>> math.pi                   # 取圆周率
3.141592653589793
>>> math.e                    # 自然常数
2.718281828459045
>>> math.pow(2, 3)            # 幂次方运算
8.0
>>> math.sqrt(7)              # 开平方根
2.6457513110645907

3、os

作业:操作系统文件系统

>>> dir(os)
['abc', 'abort', 'access', 'add_dll_directory', 'altsep', 'chdir', 'chmod', 'close', 'closerange', 'cpu_count', 'curdir', 'defpath', 'device_encoding', 'devnull', 'dup', 'dup2', 'environ', 'error', 'execl', 'execle', 'execlp', 'execlpe', 'execv', 'execve', 'execvp', 'execvpe', 'extsep', 'fdopen', 'fsdecode', 'fsencode', 'fspath', 'fstat', 'fsync', 'ftruncate', 'get_exec_path', 'get_handle_inheritable', 'get_inheritable', 'get_terminal_size', 'getcwd', 'getcwdb', 'getenv', 'getlogin', 'getpid', 'getppid', 'isatty', 'kill', 'linesep', 'link', 'listdir', 'lseek', 'lstat', 'makedirs', 'mkdir', 'name', 'open', 'pardir', 'path', 'pathsep', 'pipe', 'popen', 'putenv', 'read', 'readlink', 'remove', 'removedirs', 'rename', 'renames', 'replace', 'rmdir', 'scandir', 'sep', 'set_handle_inheritable', 'set_inheritable', 'spawnl', 'spawnle', 'spawnv', 'spawnve', 'st', 'startfile', 'stat', 'stat_result', 'statvfs_result', 'strerror', 'supports_bytes_environ', 'supports_dir_fd', 'supports_effective_ids', 'supports_fd', 'supports_follow_symlinks', 'symlink', 'sys', 'system', 'terminal_size', 'times', 'times_result', 'truncate', 'umask', 'uname_result', 'unlink', 'urandom', 'utime', 'waitpid', 'walk', 'write']
>>> os.system('cls')                       # 执行操作系统命令
0
>>> os.curdir                              # 返回当前目录(相对)
'.'
>>> os.path.abspath(os.curdir)             # 返回当前目录(绝对)
'C:\\Windows\\system32'
>>> os.chdir("C:\\ProgramData\\NVIDIA")    # 切换工作目录
>>> os.path.abspath(os.curdir)
'C:\\ProgramData\\NVIDIA'
>>> os.cpu_count()                         # 统计计算机cpu线程数
8
>>> os.getcwd()                            # 返回当前绝对路径
'C:\\ProgramData\\NVIDIA'
getpid()                                   # 获取当前进程的进程编号
getppid()                                  # 获取当前进程的父进程的编程
kill()                                     # 通过进程编号杀死进程
>>> os.linesep                             # 查看操作系统换行符
'\r\n'
>>> os.listdir()                           # 查看当前目录下文件夹以及文件
['.jetbrains', 'AccountPictures', 'Desktop', 'desktop.ini', 'Documents', 'Downloads', 'Foxit Software', 'Libraries', 'Music', 'Nwt', 'Pictures', 'SogouInput', 'Thunder Network', 'Videos']
>>> os.mkdir("C:\\Users\\Public\\wan")     # 创建目录,仅支持创建一层目录
>>> os.makedirs("C:\\Users\\Public\\wan\\a\\b\\c\\d")      # 创建目录,仅支持递归创建
open()                                     # 打开文件
>>> os.pathsep                            # 查看系统环境变量分隔符
';'
>>> os.sep                                # 查看系统路径的分隔符
'\\'
>>> os.remove("wan.txt")                  # 删除指定文件
>>> os.removedirs('wan')               # 删除指定目录(支持多级删除)

4、os.path

作用:用于获取文件的属性

>>> import os.path as p
>>> dir(p)
['abspath', 'altsep', 'basename', 'commonpath', 'commonprefix', 'curdir', 'defpath', 'devnull', 'dirname', 'exists', 'expanduser', 'expandvars', 'extsep', 'genericpath', 'getatime', 'getctime', 'getmtime', 'getsize', 'isabs', 'isdir', 'isfile', 'islink', 'ismount', 'join', 'lexists', 'normcase', 'normpath', 'os', 'pardir', 'pathsep', 'realpath', 'relpath', 'samefile', 'sameopenfile', 'samestat', 'sep', 'split', 'splitdrive', 'splitext', 'stat', 'supports_unicode_filenames', 'sys']
>>> p.abspath('.')               # 返回路径的绝对路径
'C:\\Users\\DELL'
>>> p.realpath('.')              # 返回路径的绝对路径
'C:\\Windows\\System32'
>>> help(p.altsep)               # 用来查看python中各种符号
Operator precedence
*******************The following table summarizes the operator precedence in Python, from
lowest precedence (least binding) to highest precedence (most
binding).  Operators in the same box have the same precedence.  Unless
the syntax is explicitly given, operators are binary.  Operators in
the same box group left to right (except for exponentiation, which
groups from right to left).Note that comparisons, membership tests, and identity tests, all have
the same precedence and have a left-to-right chaining feature as
described in the Comparisons section.+-------------------------------------------------+---------------------------------------+
| Operator                                        | Description                           |
|=================================================|=======================================|
| ":="                                            | Assignment expression                 |
+-------------------------------------------------+---------------------------------------+
| "lambda"                                        | Lambda expression                     |
+-------------------------------------------------+---------------------------------------+
| "if" – "else"                                   | Conditional expression                |
+-------------------------------------------------+---------------------------------------+
| "or"                                            | Boolean OR                            |
+-------------------------------------------------+---------------------------------------+
| "and"                                           | Boolean AND                           |
+-------------------------------------------------+---------------------------------------+
| "not" "x"                                       | Boolean NOT                           |
+-------------------------------------------------+---------------------------------------+
| "in", "not in", "is", "is not", "<", "<=", ">", | Comparisons, including membership     |
| ">=", "!=", "=="                                | tests and identity tests              |
+-------------------------------------------------+---------------------------------------+
| "|"                                             | Bitwise OR                            |
+-------------------------------------------------+---------------------------------------+
| "^"                                             | Bitwise XOR                           |
+-------------------------------------------------+---------------------------------------+
| "&"                                             | Bitwise AND                           |
+-------------------------------------------------+---------------------------------------+
| "<<", ">>"                                      | Shifts                                |
+-------------------------------------------------+---------------------------------------+
| "+", "-"                                        | Addition and subtraction              |
+-------------------------------------------------+---------------------------------------+
| "*", "@", "/", "//", "%"                        | Multiplication, matrix                |
|                                                 | multiplication, division, floor       |
|                                                 | division, remainder [5]               |
+-------------------------------------------------+---------------------------------------+
| "+x", "-x", "~x"                                | Positive, negative, bitwise NOT       |
+-------------------------------------------------+---------------------------------------+
| "**"                                            | Exponentiation [6]                    |
+-------------------------------------------------+---------------------------------------+
| "await" "x"                                     | Await expression                      |
+-------------------------------------------------+---------------------------------------+
| "x[index]", "x[index:index]",                   | Subscription, slicing, call,          |
| "x(arguments...)", "x.attribute"                | attribute reference                   |
+-------------------------------------------------+---------------------------------------+
| "(expressions...)",  "[expressions...]", "{key: | Binding or parenthesized expression,  |
| value...}", "{expressions...}"                  | list display, dictionary display, set |
|                                                 | display                               |
+-------------------------------------------------+---------------------------------------+
... ...>>> p.basename('E:\\openlab--Training\\Python--刘建宏\\3.26\\遍历磁盘.py')     # 获取文件名
'遍历磁盘.py'
>>> p.dirname('E:\\openlab--Training\\Python--刘建宏\\3.26\\遍历磁盘.py')      # 获取路径
'E:\\openlab--Training\\Python--刘建宏\\3.26'
>>> p.curdir                                                                # 返回相对路径
'.'
>>> p.exists('E:\\openlab--Training\\Python--刘建宏\\3.26\\遍历磁盘.py')       # 判断目录或者文件是否存在
True
>>> p.getctime('E:\\openlab--Training\\Python--刘建宏\\3.26\\遍历磁盘.py')     # 获取文件的创建时间
1585210654.3121617
>>> p.getmtime('E:\\openlab--Training\\Python--刘建宏\\3.26\\遍历磁盘.py')      # 获取文件内容修改时间
1585210653.45535
>>> p.getatime('E:\\openlab--Training\\Python--刘建宏\\3.26\\遍历磁盘.py')     # 获取文件的元数据修改时间
1627211302.8820622
>>> p.getsize('E:\\openlab--Training\\Python--刘建宏\\3.26\\遍历磁盘.py')      # 获取文件或者文件夹字节大小
684
>>> p.isdir('E:\\openlab--Training\\Python--刘建宏\\3.26\\')                  # 判断是否为目录
True
>>> p.isfile('E:\\openlab--Training\\Python--刘建宏\\3.26\\遍历磁盘.py')       # 判断是否为文件
True
>>> p.isabs('E:\\openlab--Training\\Python--刘建宏\\3.26\\')                  # 判断是否为绝对路径
True
islink                                                                       # 判断是否为链接文件
ismount                                                                      # 判断是否为挂载文件
>>> file_name = 'wan.txt'                                                    # 拼接文件路径和文件名
>>> url = 'c:/user/system/info/'
>>> p.join(url, file_name)
'c:/user/system/info/wan.txt'
>>> p.sep                                                                   # 查看路径分隔符
'\\'
>>> p.split('E:\\openlab--Training\\Python--刘建宏\\3.26\\遍历磁盘.py')        # 返回文件的路径和文件名(元组)
('E:\\openlab--Training\\Python--刘建宏\\3.26', '遍历磁盘.py')

练习

import os
from os import pathdef scanner_file(url):files = os.listdir(url)for f in files:# real_path = url + "\\" + f# real_path = path.join(url, f)real_path = path.join(url, f)if path.isfile(real_path):print(path.abspath(real_path))elif path.isdir(real_path):scanner_file(real_path)else:print("其他情况")scanner_file("D:\\软件安装包")

5、sys

作用:提供了许多函数和变量来处理 Python 运行时环境的不同部分

>>> import sys
>>> dir(sys)
['addaudithook', 'api_version', 'argv', 'audit', 'base_exec_prefix', 'base_prefix', 'breakpointhook', 'builtin_module_names', 'byteorder', 'call_tracing', 'callstats', 'copyright', 'displayhook', 'dllhandle', 'dont_write_bytecode', 'exc_info', 'excepthook', 'exec_prefix', 'executable', 'exit', 'flags', 'float_info', 'float_repr_style', 'get_asyncgen_hooks', 'get_coroutine_origin_tracking_depth', 'getallocatedblocks', 'getcheckinterval', 'getdefaultencoding', 'getfilesystemencodeerrors', 'getfilesystemencoding', 'getprofile', 'getrecursionlimit', 'getrefcount', 'getsizeof', 'getswitchinterval', 'gettrace', 'getwindowsversion', 'hash_info', 'hexversion', 'implementation', 'int_info', 'intern', 'is_finalizing', 'maxsize', 'maxunicode', 'meta_path', 'modules', 'path', 'path_hooks', 'path_importer_cache', 'platform', 'prefix', 'ps1', 'ps2', 'pycache_prefix', 'set_asyncgen_hooks', 'set_coroutine_origin_tracking_depth', 'setcheckinterval', 'setprofile', 'setrecursionlimit', 'setswitchinterval', 'settrace', 'stderr', 'stdin', 'stdout', 'thread_info', 'unraisablehook', 'version', 'version_info', 'warnoptions', 'winver']
>>> sys.api_version                 # 查看Python内部版本号
1013
>>> sys.argv                        # 接受脚本参数,第一个参数是脚本名(类似于shell位置变量)
['']
>>> sys.copyright                  # 查看Python版权信息
'Copyright (c) 2001-2020 Python Software Foundation.\nAll Rights Reserved.\n\nCopyright (c) 2000 BeOpen.com.\nAll Rights Reserved.\n\nCopyright (c) 1995-2001 Corporation for National Research Initiatives.\nAll Rights Reserved.\n\nCopyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam.\nAll Rights Reserved.'
>>> sys.exit()                     # 退出系统C:\Windows\system32>
>>> sys.getdefaultencoding()       # 获取解释器编码
'utf-8'
>>> sys.getfilesystemencoding()        # 获取文件系统编码
'utf-8'
>>> sys.getrecursionlimit()            # 获取Python递归限制层数(默认1000层)
1000
>>> sys.setrecursionlimit(8000)        # 设置Python递归限制层数
>>> sys.getrecursionlimit()
8000
>>> s = [1, 2, 3, 4]              # 获取Python对象的引用计数
>>> sys.getrefcount(s)
2
>>> ss = s
>>> sys.getrefcount(s)
3
>>> sys.getwindowsversion()            # 获取窗口大小
sys.getwindowsversion(major=10, minor=0, build=18363, platform=2, service_pack='')
>>> sys.version                        # 获取Python版本信息
'3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 23:03:10) [MSC v.1916 64 bit (AMD64)]'
>>> sys.version_info               # 获取Python版本信息
sys.version_info(major=3, minor=8, micro=2, releaselevel='final', serial=0)

Python的垃圾回收原理:引用计数为主,以标记清除和分带收集为辅

6、hashlib

作用:hash加密

算法分类:

按照算法是否可逆分类

  • 可逆算法

    • 对称加密算法

      加密与解密使用同一把秘钥

      DES

      SEDS

      AES

      IDEA

    • 非对称加密算法

      加密与解密使用不同的秘钥(公钥/私钥)

      RSA

      DH

      DSA

      EC

  • 非可逆算法

    特地:不可逆行、唯一性、雪崩效应

    • hash

      MD5

      SHA

      HMAC

>>> import hashlib
>>> dir(hashlib)
['__all__', '__block_openssl_constructor', '__builtin_constructor_cache', '__builtins__', '__cached__', '__doc__', '__file__', '__get_builtin_constructor', '__loader__', '__name__', '__package__', '__spec__', '_hashlib', 'algorithms_available', 'algorithms_guaranteed', 'blake2b', 'blake2s', 'md5', 'new', 'pbkdf2_hmac', 'scrypt', 'sha1', 'sha224', 'sha256', 'sha384', 'sha3_224', 'sha3_256', 'sha3_384', 'sha3_512', 'sha512', 'shake_128', 'shake_256']
# hash 加密使用方法:
>>> md5 = hashlib.md5("hello python".encode("utf-8"))
>>> md5
<md5 HASH object @ 0x00000154A70C7C10>
>>> md5.hexdigest()
'e53024684c9be1dd3f6114ecc8bbdddc'
# 使用update颜值混淆加密
>>> md5 = hashlib.md5("hello python".encode("utf-8"))
>>> md5.hexdigest()
'e53024684c9be1dd3f6114ecc8bbdddc'
>>> md5.update("xnudsy832d0ws2h*&^$%$%VY&".encode("utf-8"))
>>> md5.hexdigest()
'f2da0a61a7e483d9b1df742958eb0244'

应用:

  • 数据校验,安全检查 ---- 不需要做盐值混淆
  • 数据库传输 ---- 需要做盐值混淆

注意:hashlib中所有hash算法操作方法雷同

用途:数字摘要,密码信息加密

7、hmac

作用:对称加密 + hash加密

>>> import hmac
>>> dir(hmac)
['HMAC', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_hashlib', '_hashopenssl', '_openssl_md_meths', '_warnings', 'compare_digest', 'digest', 'digest_size', 'new', 'trans_36', 'trans_5C']
# 先进行对称加密,在进行MD5加密
>>> hmac = hmac.new("123456".encode("utf-8"), "zhangwanqiang".encode("utf-8"), "MD5")
>>> hmac.hexdigest()
'eb4ee22adc6a3f77696703f21d65ac07'

用途:密码信息加密(安全性较高)

8、time

作用:时间相关

>>> import time
>>> dir(time)
['_STRUCT_TM_ITEMS', '__doc__', '__loader__', '__name__', '__package__', '__spec__', 'altzone', 'asctime', 'ctime', 'daylight', 'get_clock_info', 'gmtime', 'localtime', 'mktime', 'monotonic', 'monotonic_ns', 'perf_counter', 'perf_counter_ns', 'process_time', 'process_time_ns', 'sleep', 'strftime', 'strptime', 'struct_time', 'thread_time', 'thread_time_ns', 'time', 'time_ns', 'timezone', 'tzname']
>>> time.asctime()                           # 获取当前时间
'Tue Jul 27 16:54:56 2021'
>>> time.ctime()                            # 获取当前时间
'Tue Jul 27 17:16:23 2021'
>>> time.localtime()                        # 获取本地时间
time.struct_time(tm_year=2021, tm_mon=7, tm_mday=27, tm_hour=16, tm_min=55, tm_sec=18, tm_wday=1, tm_yday=208, tm_isdst=0)
>>> ltime = time.localtime()
>>> ltime.tm_year
2021
>>> ltime.tm_mon
7
>>> ltime.tm_mday
27
>>> print("%s-%s-%s %s:%s:%s" %(ltime.tm_year, ltime.tm_mon, ltime.tm_mday, ltime.tm_hour, ltime.tm_min, ltime.tm_sec))                                # 获取本地时间(方便格式化时间显示)
2021-7-27 16:58:17
>>> time.sleep(10)                          # 程序休眠10s
>>> time.time()                                 # 获取时间戳(1970-7-1 0:0:0 到当前时间的秒数)
1627377088.9805143
>>> time.strftime("%Y-%m-%d %H:%M:%S")        # 时间对象格式化显示,转换成字符串
'2021-07-27 17:19:30'
>>> ss = "2008-08-08 08:08:08"               # 将字符串转换为时间对象
>>> time.strptime(ss, "%Y-%m-%d %H:%M:%S")
time.struct_time(tm_year=2008, tm_mon=8, tm_mday=8, tm_hour=8, tm_min=8, tm_sec=8, tm_wday=4, tm_yday=221, tm_isdst=-1)

9、datetime

作用:时间相关(是对time模块的补充)

>>> import datetime
>>> dir(datetime)
['MAXYEAR', 'MINYEAR', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'date', 'datetime', 'datetime_CAPI', 'sys', 'time', 'timedelta', 'timezone', 'tzinfo']
>>> from datetime import datetime
>>> dir(datetime)
['__add__', '__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__ne__', '__new__', '__radd__', '__reduce__', '__reduce_ex__', '__repr__', '__rsub__', '__setattr__', '__sizeof__', '__str__', '__sub__', '__subclasshook__', 'astimezone', 'combine', 'ctime', 'date', 'day', 'dst', 'fold', 'fromisocalendar', 'fromisoformat', 'fromordinal', 'fromtimestamp', 'hour', 'isocalendar', 'isoformat', 'isoweekday', 'max', 'microsecond', 'min', 'minute', 'month', 'now', 'replace', 'resolution', 'second', 'strftime', 'strptime', 'time', 'timestamp', 'timetuple', 'timetz', 'today', 'toordinal', 'tzinfo', 'tzname', 'utcfromtimestamp', 'utcnow', 'utcoffset', 'utctimetuple', 'weekday', 'year']
>>> datetime.now()                           # 获取当前时间
datetime.datetime(2021, 7, 27, 17, 32, 28, 13861)

10、calendar

作用:日历相关模块

>>> import calendar
>>> dir(calendar)
['Calendar', 'EPOCH', 'FRIDAY', 'February', 'HTMLCalendar', 'IllegalMonthError', 'IllegalWeekdayError', 'January', 'LocaleHTMLCalendar', 'LocaleTextCalendar', 'MONDAY', 'SATURDAY', 'SUNDAY', 'THURSDAY', 'TUESDAY', 'TextCalendar', 'WEDNESDAY', '_EPOCH_ORD', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_colwidth', '_locale', '_localized_day', '_localized_month', '_monthlen', '_nextmonth', '_prevmonth', '_spacing', 'c', 'calendar', 'datetime', 'day_abbr', 'day_name', 'different_locale', 'error', 'firstweekday', 'format', 'formatstring', 'isleap', 'leapdays', 'main', 'mdays', 'month', 'month_abbr', 'month_name', 'monthcalendar', 'monthrange', 'prcal', 'prmonth', 'prweek', 'repeat', 'setfirstweekday', 'sys', 'timegm', 'week', 'weekday', 'weekheader']

11、UUID

作用:获取用不重复的字符串

>>> import uuid
>>> dir(uuid)
['Enum', 'NAMESPACE_DNS', 'NAMESPACE_OID', 'NAMESPACE_URL', 'NAMESPACE_X500', 'RESERVED_FUTURE', 'RESERVED_MICROSOFT', 'RESERVED_NCS', 'RFC_4122', 'SafeUUID', 'UUID', '_AIX', '_DARWIN', '_GETTERS', '_LINUX', '_OS_GETTERS', '_UuidCreate', '_WINDOWS', '__author__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_arp_getnode', '_find_mac', '_generate_time_safe', '_has_uuid_generate_time_safe', '_ifconfig_getnode', '_ip_getnode', '_ipconfig_getnode', '_is_universal', '_lanscan_getnode', '_last_timestamp', '_load_system_functions', '_netbios_getnode', '_netstat_getnode', '_node', '_popen', '_random_getnode', '_unix_getnode', '_uuid', '_windll_getnode', 'bytes_', 'getnode', 'int_', 'os', 'platform', 'sys', 'uuid1', 'uuid3', 'uuid4', 'uuid5']
>>> uuid.uuid4()                            # 获取用不重复的字符串,每次获取都不相同
UUID('c6e232f2-f55c-4918-b0ac-397cd5f5d518')
>>> uuid.uuid4().hex
'abe6f101edc448c4b9de6828e709c8e2'
>>> uuid.uuid4().hex
'e41a9b3e006c45ee9c5c43f3e1e64ba8'
>>> uuid.uuid4().hex
'4a22a06747a042c6ac536500e907c9a4'
>>> uuid.uuid4().hex
'7300954d813b40dcace0606d02c531b9

Python 常用模块总结相关推荐

  1. 实战篇一 python常用模块和库介绍

    # -_-@ coding: utf-8 -_-@ -- Python 常用模块和库介绍 第一部分:json模块介绍 import json 将一个Python数据结构转换为JSON: dict_ = ...

  2. python常用模块大全总结-常用python模块

    广告关闭 2017年12月,云+社区对外发布,从最开始的技术博客到现在拥有多个社区产品.未来,我们一起乘风破浪,创造无限可能. python常用模块什么是模块? 常见的场景:一个模块就是一个包含了py ...

  3. 对于python来说、一个模块就是一个文件-python常用模块

    python常用模块 什么是模块? 常见的场景:一个模块就是一个包含了python定义和声明的文件,文件名就是模块名字加上.py的后缀. 但其实import加载的模块分为四个通用类别: 1 使用pyt ...

  4. python常用模块之shelve模块

    python常用模块之shelve模块 shelve模块是一个简单的k,v将内存中的数据通过文件持久化的模块,可以持久化任何pickle可支持的python数据类型 我们在上面讲json.pickle ...

  5. Python常用模块——目录

    Python常用模块学习 Python模块和包 Python常用模块time & datetime &random 模块 Python常用模块os & sys & sh ...

  6. Python常用模块集锦

    常用模块主要分为以下几类(缺失的后续再补充): 时间转换 时间计算 序列化和反序列化:json,pickle 编解码:unicode,base64 加解密:md5,sha1,hmac_sha1,aes ...

  7. Python+常用模块(2).md

    Python 常用模块 1. random模块 1.1 导入模块 import random 1.2 random.random() 生成一个从0到1的随机浮点数 1.3 random.uniform ...

  8. python用什么来写模块-Python常用模块——模块介绍与导入

    Python常用模块--模块介绍与导入 一.什么是模块? 在计算机程序的开发过程中,随着程序代码越写越多,在一个文件里代码就会越来越长,越来越不容易维护. 为了编写可维护的代码,我们把很多函数分组,分 ...

  9. python常用模块-调用系统命令模块(subprocess)

    python常用模块-调用系统命令模块(subprocess) 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. subproces基本上就是为了取代os.system和os.spaw ...

最新文章

  1. 广州企业“掘金”物联网蓝海
  2. python读取excel-Python中使用第三方库xlrd来读取Excel示例
  3. 【Flutter】Flutter 混合开发 ( Flutter 与 Native 通信 | 通信场景 | Channel 通信机制 | Channel 支持的通信数据类型 | Channel 类型 )
  4. SQL Server创建存储过程
  5. 剑指Offer #12 数值的整数次方(快速幂)
  6. 用js参数实现模板替换机制
  7. 微型计算机原理及应用程序题,郑学坚《微型计算机原理及应用》(第4版)笔记和课后习题详解...
  8. 使 Framework 2.0 的程序集不用安装 Framework 就可以运行的工具免费发布了
  9. mongodb创建local库用户_mongodb用户与角色使用
  10. 充分掌握网络工作原理及底层实现 大家都做什么项目啊?
  11. 上行和下行是什么意思_为什么无线通信需要同步?
  12. Django-组件拾遗
  13. 软考软件设计师下午真题-面向对象的程序设计与实现-装饰设计模式(2012年上半年试题六))Java代码讲解
  14. 转:13个大数据应用案例,告诉你最真实的大数据故事
  15. Django中URL和View的关系
  16. 【C语言】算法学习·哈希算法全解
  17. 知识图谱可视化工具选型
  18. 计算机重启 ie 被改,ie被修改怎么办 ie被修改的解决方法【详解】
  19. 商标设计后一定要向商标局进行重新提交,商标持有公司变更后要及时变更商标
  20. 笔记:利用易宝第三方支付实现简单支付的功能

热门文章

  1. 有效管理自己知识,多总结和分享——2018七月份的尾巴
  2. 据说是11年度最佳代码
  3. php 动态网格,ZBrush中的动态网格该怎么进行运用
  4. Linux高级查询命令
  5. python画矩阵图_Python可视化25_seaborn绘制矩阵图
  6. html+css+javascript代码编程规范之CSS
  7. android手机做个人网盘,[干货Get!]Android搭建Cloudreve私人云盘 来自 kindyear
  8. 久等了! AI 时代的编程语言
  9. 磁盘管理-Linux系统磁盘管理
  10. vgg16卷积层的计算量_卷积神经网络VGG16详解