python - 从python 3中的字节中删除一些特定内容
问题描述
我不知道如何从以下字节中删除 '\x00'。目前,我正在尝试将此字节写入 python 3 中的文本文件。
b'Today, in the digital age, any type of data, such as text, images, and
audio, can be\r\ndigitized, stored indefinitely, and transmitted at high
speeds. Notwithstanding these\r\nadvantages, digital data also have a
downside. They are easy to access illegally, tamper\r\nwith, and copy for
purposes of copyright violation.\r\nThere is therefore a need to hide secret
identification inside certain types of digital\r\ndata. This information can
be used to prove copyright ownership, to identify attempts\r\nto tamper with
sensitive data, and to embed annotations. Storing, hiding, or embedding\r
\nsecret information in all types of digital data is one of the tasks of the
field of\r\nsteganography.\r\nSteganography is the art and science of data
hiding. In contrast with cryptography,\r\nwhich secures data by transforming
it into another, unreadable format, steganography\r\nmakes data invisible by
hiding (or embedding) them in another piece of data, known\r\nalternatively as
the cover, the host, or the carrier. The modified cover, including
the\r\nhidden data, is referred to as a stego object. It can be stored or
transmitted as a message.\r\nWe can think of cryptography as overt secret
writing and of steganography as covert\r\nsecret writing.\x00\x00\x00\x00\x00
\x00\x00\x00\x00\x00\x00\x00\x00'
我想从句\x00
尾删除多个。请帮我!
解决方案
用于bytes.replace
用空字符串替换子字符串:
b = b'Today, in the digital age, any type of data, such as text, images, and audio, can be\r\ndigitized, stored indefinitely, and transmitted at high speeds. Notwithstanding these\r\nadvantages, digital data also have a downside. They are easy to access illegally, tamper\r\nwith, and copy for purposes of copyright violation.\r\nThere is therefore a need to hide secret identification inside certain types of digital\r\ndata. This information can be used to prove copyright ownership, to identify attempts\r\nto tamper with sensitive data, and to embed annotations. Storing, hiding, or embedding\r\nsecret information in all types of digital data is one of the tasks of the field of\r\nsteganography.\r\nSteganography is the art and science of data hiding. In contrast with cryptography,\r\nwhich secures data by transforming it into another, unreadable format, steganography\r\nmakes data invisible by hiding (or embedding) them in another piece of data, known\r\nalternatively as the cover, the host, or the carrier. The modified cover, including the\r\nhidden data, is referred to as a stego object. It can be stored or transmitted as a message.\r\nWe can think of cryptography as overt secret writing and of steganography as covert\r\nsecret writing.\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
b = b.replace(b'\x00', b'')
assert b.endswith(b'writing.')
推荐阅读
- alpine.js - Focus an input on select change with Alpine.js
- flask - 重定向到同一页面但添加动态路由
- php - CakePHP DC 用户 8.5.1 自定义使用电子邮件
- cucumber - webdriverio cucumber outline // play all scenarios even if one is having a failure
- python - How to overcome this Index error in Python
- python - 如何从具有 PySide2 GUI 的 python 脚本构建一个 mac os 应用程序?
- runtime - 现在工作了一年多的makro问题(运行时1004)
- node.js - Azure AD 使用 Passport.js 对访问令牌进行无效签名
- css - 如何使用 ::ng-deep 访问 Angular 子组件的 CSS
- c++ - 在线程之间协调哪些线程是空闲的最有效的方法是什么?