-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuery_test.py
More file actions
73 lines (47 loc) · 1.16 KB
/
Query_test.py
File metadata and controls
73 lines (47 loc) · 1.16 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from contextlib import contextmanager, closing
#from string import *
from urllib.request import urlopen
urlopen('https://www.baidu.com')
#class Query():
# def __init__(self,name):
# self.name=name
# def __enter__(self):
# print('Begin')
# return self
# def __exit__(self, exc_type,exc_value,traceback):
# if exc_type:
# print('Error')
# else:
# print('End')
# def query(self):
# print("Query info about {}".format(self.name))
#with Query('Bob') as q:
# q.query()
## contextmanager for adding context for the code
#class Query():
# def __init__(self,name):
# self.name=name
# def query(self):
# print("Query info about {}".format(self.name))
#@contextmanager
#def add_context(name):
# print('Begin')
# q=Query(name)
# yield q
# print('End')
#with add_context('Bob') as p:
# p.query()
## contextmanager for adding fixed context for the code
#@contextmanager
#def fix_context(var):
# print("<{}>".format(var))
# yield
# print("<\{}>".format(var))
#with fix_context('h'):
# print("This is a test")
print('OK')
#print(urlopen('https://www.baidu.com'))
#input('')
#with closing(urlopen('https://baidu.com')) as page:
# for line in page:
# print(line)