进度条的打印

  import sys,time

  for i in range(20):
    sys.stdout.write('$')      #stdout是标准输出的意思,在一般电脑上,stdout的标准输出指的是计算机屏幕。
    sys.stdout.flush()
    time.sleep(0.1)

单线程下的并发运算:

import time
def consumer(name):
print("%s 准备吃包子啦!" %name)
while True:
baozi = yield
print("包子[%s]来了,被[%s]吃了!" %(baozi,name)) def producer(name):
c = consumer('A')
c2 = consumer('B')
c.__next__()
c2.__next__()
print("老子开始准备做包子啦!")
for i in range(10):
time.sleep(1)
print("做了2个包子!")
c.send(i)
c2.send(i) producer("gavin")

生成数字+字母的验证码的小程序

__author__ = "Gavin"
import random
checkcode=''
for i in range(5):
  current=random.randrange(0,5)
  if current == i:
    tmp=chr(random.randint(65,90))
  else:
    tmp=random.randint(0,9)
  checkcode+=str(tmp)
print(checkcode)

异步I/O写的SocketServer

使用协程的方式,执行效率极高

server side 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import sys
import socket
import time
import gevent
 
from gevent import socket,monkey
monkey.patch_all()
 
 
def server(port):
    = socket.socket()
    s.bind(('0.0.0.0', port))
    s.listen(500)
    while True:
        cli, addr = s.accept()
        gevent.spawn(handle_request, cli)
 
 
 
def handle_request(conn):
    try:
        while True:
            data = conn.recv(1024)
            print("recv:", data)
            conn.send(data)
            if not data:
                conn.shutdown(socket.SHUT_WR)
 
    except Exception as  ex:
        print(ex)
    finally:
        conn.close()
if __name__ == '__main__':
    server(8001)

  

client side   

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import socket
 
HOST = 'localhost'    # The remote host
PORT = 8001           # The same port as used by the server
= socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
while True:
    msg = bytes(input(">>:"),encoding="utf8")
    s.sendall(msg)
    data = s.recv(1024)
    #print(data)
 
    print('Received'repr(data))
s.close()

自己写的缓存系统

Python全栈开发-有趣的小程序的更多相关文章

  1. 全栈开发工程师微信小程序-中(下)

    全栈开发工程师微信小程序-中(下) 微信小程序视图层 wxml用于描述页面的结构,wxss用于描述页面的样式,组件用于视图的基本组成单元. // 绑定数据 index.wxml <view> ...

  2. 全栈开发工程师微信小程序-中(中)

    全栈开发工程师微信小程序-中(中) 开放能力 open-data 用于展示微信开放的数据 type 开放数据类型 open-gid 当 type="groupName" 时生效, ...

  3. 全栈开发工程师微信小程序-中

    全栈开发工程师微信小程序-中 多媒体及其他的组件 navigator 页面链接 target 在哪个目标上发生跳转,默认当前小程序,可选值self/miniProgram url 当前小程序内的跳转链 ...

  4. 全栈开发工程师微信小程序-上(下)

    全栈开发工程师微信小程序-上(下) icon 图标 success, success_no_circle, info, warn, waiting, cancel, download, search, ...

  5. 全栈开发工程师微信小程序-上(中)

    全栈开发工程师微信小程序-上(中) width: 750rpx; 750rpx代表与屏幕等宽,rpx的缩写responsive pixel,这个单位是可以根据屏幕大小进行自适应调整的像素单位. 小程序 ...

  6. 全栈开发工程师微信小程序 - 上

    全栈开发工程师微信小程序-上 实现swiper组件 swiper 滑块视图容器. indicator-dots 是否显示面板指示点 false indicator-color 指示点颜色 indica ...

  7. 全栈开发工程师微信小程序-下

    app.json { "pages": ["pages/index/index"] } index.wxml <text>Hello World&l ...

  8. Python全栈开发【面向对象进阶】

    Python全栈开发[面向对象进阶] 本节内容: isinstance(obj,cls)和issubclass(sub,super) 反射 __setattr__,__delattr__,__geta ...

  9. Python全栈开发【面向对象】

    Python全栈开发[面向对象] 本节内容: 三大编程范式 面向对象设计与面向对象编程 类和对象 静态属性.类方法.静态方法 类组合 继承 多态 封装 三大编程范式 三大编程范式: 1.面向过程编程 ...

随机推荐

  1. neutron full stack

    1.  通读一下 neutron的那个文档.  里面介绍了, db怎么隔离的, amqp怎么隔离的. 2.  记住文档中,那个full stack的图. 3.  走读代码      从TestOvsC ...

  2. oracle RAC如何正确地删除ASM磁盘组

    1.登录到命令行 切换到grid用户 [grid@swnode1 ~]$ sqlplus / as sysasm SQL*Plus: Release Production on Wed May :: ...

  3. opencv学习之路(9)、对比度亮度调整与通道分离

    一.对比度亮度调整 #include<opencv2/opencv.hpp> using namespace cv; #define WIN_NAME "输出图像" M ...

  4. 基础_cifar10_model

    今天进一步在cifar10数据集上解决几个问题: 1.比较一下序贯和model,为什么要分成两块: 2.同样的条件下,我去比较一下序贯和model.这个例子作为今天的晚间运行. 1.比较一下序贯和mo ...

  5. vue中如何使用echarts

    在vue中使用echarts主要是注意如何与vue生命周期相结合,从而做到数据驱动视图刷新 主要是以下几步: echarts的option配置项放在在data(){}或者computed(){}中 在 ...

  6. Codeforces 711D Directed Roads - 组合数学

    ZS the Coder and Chris the Baboon has explored Udayland for quite some time. They realize that it co ...

  7. Codeforces 772A Voltage Keepsake - 二分答案

    You have n devices that you want to use simultaneously. The i-th device uses ai units of power per s ...

  8. log4j2的配置及使用

    log4j2与log4j1的不同点(不完整): 前者配置文件格式多样性.log4j2的配置文件可以是xml,也可以是json. 在不修改web.xml的前提下,前者配置文件的命名可以为log4j2.x ...

  9. 【ContextLoaderListener】Web项目启动报错java.lang.ClassNotFoundException: ContextLoaderListener

    错误原因: 进入到tomcat的部署路径.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\下检查了一下,发现工程部署后在WE ...

  10. 题解——Codeforces Round #507 (based on Olympiad of Metropolises) T1 (模拟)

    暴力模拟即可 就是情况略多 #include <cstdio> #include <algorithm> #include <cstring> using name ...