当前位置:网站首页>3. File operation 3-with

3. File operation 3-with

2022-07-06 08:17:00 wwanxinghao

1、with: Benefits: no need to close files manually (f.close())

The following is a simple operation of reading files

with open(' New files .txt',mode='r' ,encoding='utf-8') as f:
    for i in f:
        print(i.strip())

2、 The following validation with No use close()

3、 Pattern mode='rb', Yes Read non text , Namely , Audio , video , Picture these , These are not stored in strings , It is stored in bytes ;mode='wb', Write audio , video , Picture these data ( They are stored in bytes )

The following example is , Will a mp4 The operation of assigning a copy to a file

原网站

版权声明
本文为[wwanxinghao]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202131833015196.html