国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

python實現在內存中讀寫str和二進制數據代碼

瀏覽:7日期:2022-07-27 16:54:26

我就廢話不多說了,還是直接看代碼吧!

# 利用python在內存中讀寫str和二進制數據from io import StringIOfrom io import BytesIO f = StringIO()print(f.write(’hello ’)) # 6print(f.write(’world!’)) # 6print(f.getvalue()) # hello world! f = BytesIO()print(f.write(’中文’.encode(’utf-8’))) # 6print(f.getvalue()) # b’xe4xb8xadxe6x96x87’

補充知識:python二進制轉到float

看代碼吧!

# -*- coding: utf-8 -*-'''Created on Tue Dec 3 14:38:04 2019@author: xuguanghui''' import numpy as np mlplib_label = r'C:UsersxuguanghuiDesktop106421_mlplib.lab'train_label = r'C:UsersxuguanghuiDesktop106421_train.lab'mlplib_txt = r'C:UsersxuguanghuiDesktop106421_mlplib.txt'train_txt = r'C:UsersxuguanghuiDesktop106421_train.txt' mlplib_lab = np.fromfile(mlplib_label, dtype=np.int32).reshape(-1, 892)train_lab = np.fromfile(train_label, dtype=np.float32).reshape(-1, 892) np.savetxt(mlplib_txt, mlplib_lab, fmt=’%d’)np.savetxt(train_txt, train_lab, fmt=’%d’)

以上這篇python實現在內存中讀寫str和二進制數據代碼就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持好吧啦網。

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 云霄县| 博野县| 布尔津县| 镇宁| 道孚县| 故城县| 禹城市| 罗平县| 徐汇区| 潜江市| 河南省| 宜良县| 沂源县| 罗山县| 屏山县| 京山县| 布拖县| 贵阳市| 灵丘县| 布尔津县| 澄城县| 江陵县| 金山区| 天全县| 府谷县| 高淳县| 桂林市| 微山县| 拉萨市| 云和县| 井研县| 泰州市| 吴川市| 遵义市| 抚州市| 北流市| 无极县| 公主岭市| 平遥县| 克什克腾旗| 濮阳市|