-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPythonWith.py
More file actions
45 lines (36 loc) · 1004 Bytes
/
PythonWith.py
File metadata and controls
45 lines (36 loc) · 1004 Bytes
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
#!/usr/bin/python
# -*- encoding:utf-8 -*-
# class test1(object):
# def __enter__(self):
# print "this is __enter__()"
# return "Foo"
# def __exit__(self,type,value,trace):
# print "this is __exit__()"
# print test1()
# with test1() as test1obj:
# print "testobj is:",test1obj
class test(object):
def __enter__(self):
return self
def __exit__(self,type,value,trace):
print "type is:",type
print "value is:",value
print "trace is:",trace
def do_something(self):
bar = 1/0
return bar+10
with test() as testobj:
tval = 1 + "2"
testobj.do_something()
# class test(object):
# def __enter__(self):
# return self
# def __exit__(self,type,value,trace):
# print "type is:",type
# print "value is:",value
# print "trace is:",trace
# def do_something(self):
# bar = 1/0
# return bar+10
# with test() as testobj:
# testobj.do_something()