Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of python operating File Mode

Shulou Source: shulou.com Published: 2022-06-03 17:38:51 09月28日 Update

This article mainly shows you the "python operation file mode example analysis", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "python operation file mode example analysis" this article.

1. Read-only mode (read-only data r).

F = open ('my_file.txt',' rb') f_bytes = f.read () print (f_bytes) print (f_bytes.decode ('utf-8')) f.close ()

2. Write-only mode (rewrite data w), write data in binary mode or append data in write-only mode.

Write_file = open ('demo1.jpg', mode='wb') read_file = open (' demo.jpg', mode='rb') write_file.write (read_file.read ()) read_file.close () write_file.close ()

3. Read-write mode (append data a). If you don't want the original data to be overwritten, you can use the way to append and write data.

Read_write_file = open ('append_file.txt', mode='r+', encoding='utf-8') print (read_write_file.read ()) read_write_file.write ('\ nstrive to make progress every day') print (read_write_file.read ()) read_write_file.close () above is all the contents of the article "sample Analysis of python operating File Mode". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Patterns data documents examples analysis content articles methods learning help daily upward binary easy to understand more organization knowledge editing industry information information channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux MySQL Xiaomi Shulou Tech Info Shulou Technology