Study Notes (18): 21 days clearance Python (Video Lesson only) - Enter the pipeline with statement

Learning immediately: https://edu.csdn.net/course/play/24797/282198?utm_source=blogtoedu

Import SYS # 
# for I in sys.stdin: 
# Print (I) 

class TestWith: 
    DEF the __init __ (Self, Tag): 
        self.tag = Tag 
        Print ( 'constructor --init--') 

    DEF The __enter __ (Self): 
        print ( 'operating method __enter__% S = Tag'% self.tag) 
        return 'enter the method returns the result' 

    '' ' 
    abnormality information 
    exc_type: exception type 
    exc_val: exception incoming value 
    exc_tb: abnormal the traceback 
    ' '' 

    DEF __ __exit (Self, exc_type, exc_val, exc_tb): 
        IF exc_tb: 
            Print ( 'where there is abnormal') 
        the else: 
            Print ( 'normal operating procedures') 


with TestWith ( 'TestWith') AS Re:
    print('re:%s' % re)
    print ( 'start') 
    # The raise Exception (2, 'error') 
    print ( 'end') 

with Open ( 'test45.py', 'R & lt', True, 'UTF-. 8') AS F: 
    for I in F : 
        Print (I, End = '')
Published 25 original articles · won praise 4 · Views 598

Guess you like

Origin blog.csdn.net/happyk213/article/details/105219969