Skip to content

Commit 8db49e2

Browse files
committed
add: part_push demo
1 parent cc38ac4 commit 8db49e2

3 files changed

Lines changed: 58 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python
2+
# -*- coding:utf-8 -*-
3+
__author__ = 'MFC'
4+
__time__ = '2020-04-28 12:50'
5+
6+
"""
7+
P17
8+
"""
9+
10+
import asyncio
11+
12+
import aiopg
13+
14+
dsn = 'dbname=aiopg user=aiopg password=passwd host=127.0.0.1'
15+
16+
# 添加少量async和await前缀,让执行SQL查询和返回结果的函数看起来接近于同步函数
17+
async def go():
18+
pool = await aiopg.create_pool(dsn)
19+
async with pool.acquire() as conn:
20+
async with conn.cursor() as cur:
21+
await cur.execute("SELECT 1")
22+
ret = []
23+
async for row in cur:
24+
ret.append(row)
25+
assert ret == [(1,)]
26+
27+
loop = asyncio.get_event_loop()
28+
loop.run_until_complete(go())

simple_demo/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env python
2+
# -*- coding:utf-8 -*-
3+
__author__ = 'MFC'
4+
__time__ = '2020-04-30 01:20'

simple_demo/part_push.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env python
2+
# -*- coding:utf-8 -*-
3+
__author__ = 'MFC'
4+
__time__ = '2020-04-30 01:20'
5+
6+
"""
7+
100个元素列表,每10个一组分段逆序打印(提交)
8+
"""
9+
10+
# l0 = [i for i in range(0,133)]
11+
l0 = [i for i in range(0,100)]
12+
13+
print(l0)
14+
print(len(l0))
15+
16+
l0.reverse() # 注意使用reverse()后l0已经变化
17+
print(l0)
18+
19+
group_list = [ l0[i:i+10] for i in range(0,len(l0),10) ]
20+
21+
print(group_list)
22+
23+
print("-"*77)
24+
25+
for group in group_list:
26+
print(group)

0 commit comments

Comments
 (0)