转换为二进制并转换回字符串

编程入门 行业动态 更新时间:2024-10-27 05:29:16
本文介绍了转换为二进制并转换回字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

嗨... 我想带一个像''supercalifragilisticexpialidocius'' 这样的字符串并将其写成二进制形式的文件 - - 这样一来,如果用户试图打开ascii文本 编辑器,那么用户就无法读取字符串。我还希望能够将二进制形成的数据读回 到字符串格式,以便它显示原始值。在Python中有没有 方法呢? 谢谢! Harlin

解决方案

Harlin Seritt写道:

嗨... 我想带一个字符串''supercalifragilisticexpialidocius'' 并将其写成二进制形式的文件 - 这样用户无法阅读 字符串以防他们尝试打开ascii文本 编辑器。我还希望能够将二进制形成的数据读回 到字符串格式,以便它显示原始值。在Python中有没有 方法呢? 谢谢! Harlin

尝试在wb模式下打开文件。 Colin W.

Harlin Seritt写道:

嗨... 我想采取像''这样的字符串supercalifragilisticexpialidocius'' 并将其写入二进制形式的文件 - 这样一来,如果用户试图打开ascii文本之类的东西,用户就无法读取字符串 编辑。我还希望能够将二进制形成的数据读回 到字符串格式,以便它显示原始值。在Python中有没有 方法呢? 谢谢! Harlin

尝试在wb模式下打开文件。 Colin W.

2月21日下午7:02,Colin J. Williams < c ... @ sympatico.cawrote:

Harlin Seritt写道:

嗨.. 。

我想带一个字符串''supercalifragilisticexpialidocius'' 并将其写入二进制文件表单 - 这样用户无法读取字符串,以防他们尝试打开ascii文本 编辑器。我还希望能够将二进制形成的数据读回 到字符串格式,以便它显示原始值。在Python中有没有 的方法呢?

谢谢!

Harlin

尝试在wb模式下打开文件。 Colin W.

感谢您的帮助。 我尝试过这样做: text =''supercalifragilisticexpialidocius'' open(''sambleb.conf'',''wb'') .write(text) 之后,我能够用文本 编辑器成功打开文件,它显示: ''supercalifragilisticexpialidocius'' 我希望它能让它出现一些奇怪的不可读文本。然后 当然能够将它转换回字符串。这是偶数吗?可能吗? 谢谢, Harlin

Hi... I would like to take a string like ''supercalifragilisticexpialidocius'' and write it to a file in binary forms -- this way a user cannot read the string in case they were try to open in something like ascii text editor. I''d also like to be able to read the binary formed data back into string format so that it shows the original value. Is there any way to do this in Python? Thanks! Harlin

解决方案

Harlin Seritt wrote:

Hi... I would like to take a string like ''supercalifragilisticexpialidocius'' and write it to a file in binary forms -- this way a user cannot read the string in case they were try to open in something like ascii text editor. I''d also like to be able to read the binary formed data back into string format so that it shows the original value. Is there any way to do this in Python? Thanks! Harlin

Try opening your file in the ''wb'' mode. Colin W.

Harlin Seritt wrote:

Hi... I would like to take a string like ''supercalifragilisticexpialidocius'' and write it to a file in binary forms -- this way a user cannot read the string in case they were try to open in something like ascii text editor. I''d also like to be able to read the binary formed data back into string format so that it shows the original value. Is there any way to do this in Python? Thanks! Harlin

Try opening your file in the ''wb'' mode. Colin W.

On Feb 21, 7:02 pm, "Colin J. Williams" <c...@sympatico.cawrote:

Harlin Seritt wrote:

Hi...

I would like to take a string like ''supercalifragilisticexpialidocius'' and write it to a file in binary forms -- this way a user cannot read the string in case they were try to open in something like ascii text editor. I''d also like to be able to read the binary formed data back into string format so that it shows the original value. Is there any way to do this in Python?

Thanks!

Harlin

Try opening your file in the ''wb'' mode. Colin W.

Thanks for the help. I tried doing this: text = ''supercalifragilisticexpialidocius'' open(''sambleb.conf'', ''wb'').write(text) Afterwards, I was able to successfully open the file with a text editor and it showed: ''supercalifragilisticexpialidocius'' I am hoping to have it show up some weird un-readable text. And then of course be able to convert it right back to a string. Is this even possible? Thanks, Harlin

更多推荐

转换为二进制并转换回字符串

本文发布于:2023-06-05 01:21:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/508975.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   字符串   换回   并转

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!