进度条的打印

  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. 翻译 Improved Word Representation Learning with Sememes

    翻译 Improved Word Representation Learning with Sememes 题目 Improved Word Representation Learning with ...

  2. CC攻击介绍及如何防御

       CC攻击介绍 CC攻击(Challenge Collapsar)是DDOS(分布式拒绝服务)的一种,前身名为Fatboy攻击,也是一种常见的网站攻击方法.攻击者借助代理服务器生成指向受害主机的合 ...

  3. linux tmux 工具使用 tmux.conf 文件

    set -g prefix ^a unbind ^b bind a send-prefix unbind '"' bind - splitw -v unbind % bind \ split ...

  4. rsync命令解析

    !rsync同步模式sync在进行同步或备份时,使用远程shell,或TCP连接远程daemon,有两种途经连接远程主机.shell模式,不需要使用配置文件,也不需要启动远端rsync.远程传输时一般 ...

  5. if语句题目练习

    #print("您好") # # count=1 #count 表示计数 # while count<=8: # print("你是小学僧吗?") # p ...

  6. Bootstrap3基础 form-group 输入框之间出现间隔

      内容 参数   OS   Windows 10 x64   browser   Firefox 65.0.2   framework     Bootstrap 3.3.7   editor    ...

  7. [NOI1995]石子合并 四边形不等式优化

    链接 https://www.luogu.org/problemnew/show/P1880 思路 总之就是很牛逼的四边形不等式优化 复杂度\(O(n^2)\) 代码 #include <ios ...

  8. JS获取节点的兄弟,父级,子级元素

    https://blog.csdn.net/duanshuyong/article/details/7562423 先说一下JS的获取方法,其要比JQUERY的方法麻烦很多,后面以JQUERY的方法作 ...

  9. 题解——loj6277 数列分块入门1(分块)

    分块裸题 然后就是记得左右边界处理和分块的初始化 忘了初始化会被卡成暴力 #include <cstdio> #include <algorithm> #include < ...

  10. Druid介绍

    Druid (大数据实时统计分析数据存储) Druid 是一个为在大数据集之上做实时统计分析而设计的开源数据存储.这个系统集合了一个面向列存储的层,一个分布式.shared-nothing的架构,和一 ...