摘要:生成器(generator)就是对象,在每次调用它的next()方法时返回一个值,直到它抛出StopIteration 要创建一个生成器需要做的一切只是写一个普通的包含yield 语句的 Python 函数。 Python 会检测对yield 的使用并将这个函数标记为一个生成器。当函数执行到yiel
阅读全文
摘要:def menu(wine, entree, dessert='pudding'): return {'wine': wine, 'entree': entree, 'dessert': dessert} #位置参数 print(menu('bordeaux', 'beef', 'bagel')) #关键字参数 print(menu(entree='beef', dessert='b...
阅读全文
摘要:import subprocess subprocess.getoutput('date') # python3 getoutput方法 import multiprocessing import time import os def whoami(name): print("I'm %s, in process %s" % (name, os.getpid())) def...
阅读全文
摘要:import time print('......') time.sleep(5) print('......')
阅读全文
摘要:列表推导式 字典推导式 集合推导式 生成器推导式
阅读全文
摘要:from datetime import datetime, date now = datetime.now() now #datetime.datetime(2016, 8, 13, 23, 7, 47, 768757) print(now.strftime('%Y-%m-%d %H:%M:%S')) #2016-08-13 23:08:04 # 检测是否是闰年 import cal...
阅读全文
摘要:#使用mkdir()创建目录 import os os.mkdir('poems') print(os.path.exists('poems')) #使用rmdir()删除目录 import os os.rmdir('poems') print(os.path.exists('poems')) #使用listdir()列出目录内容 import os os.mkdir('poems') ...
阅读全文
摘要:# 用open()创建文件 fout = open('oops.txt', 'wt') print('Oops, I created a file.', file=fout) fout.close() # 用exists()检查文件是否存在 import os print(os.path.exists('oops.txt')) # True print(os.path.exists(...
阅读全文
摘要:pip是用国内镜像源 https://pypi.python.org/http://pypi.douban.com/simple/ http://mirrors.aliyun.com/pypi/simple/
阅读全文
摘要:Nginx 和Apache 等传统Web 服务器可以更快地处理静态文件。
阅读全文