Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the use of binaries in Python

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces what is the use of binary files in Python. The introduction in this article is very detailed and has certain reference value. Interested friends must read it!

1. binary read mode

rt Read text file (default)

RB reads binary files

file_name = "C:/Users/cheng/Desktop/can.jmx"with open(file_name, 'rt', ) as can: print(can.read())

execution result

rb reads the pattern file_name = "C:/Users/cheng/Desktop/can.jmx"with open(file_name, 'rb', ) as can: print(can.read())

execution result

Read 100 bytes

file_name = "C:/Users/cheng/Desktop/can.jmx"with open(file_name, 'rb', ) as can: #Read text files, size is in characters #Read binary file, size is in bytes print(can.read(100))

execution result

File_name = "C:/Users/cheng/Desktop/can.jmx"with open(file_name, 'rb',) as can: #Define a new file new_name = 'to.jmx' with open(new_name, 'wb') as cheng: #Define the size of each read cc = 1024 * 100 while True: #Read data from existing objects content = can.read(cc) #Content read complete, end loop if not content: break #Write the read data to the new object cheng.write(content)

Implementation results:

The above is "Python binary file what to use" all the content of this article, thank you for reading! Hope to share the content to help everyone, more relevant knowledge, welcome to pay attention to the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report