File tree Expand file tree Collapse file tree
python_microservice_development Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 ())
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
2+ # -*- coding:utf-8 -*-
3+ __author__ = 'MFC'
4+ __time__ = '2020-04-30 01:20'
Original file line number Diff line number Diff line change 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 )
You can’t perform that action at this time.
0 commit comments