久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

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

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

瀏覽:6日期: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 編程
相關文章:
主站蜘蛛池模板: 萨嘎县| 玉环县| 勐海县| 莱芜市| 湛江市| 松阳县| 霍城县| 巫溪县| 海宁市| 荥经县| 甘德县| 眉山市| 元谋县| 黎川县| 华亭县| 江西省| 栾城县| 萨迦县| 修文县| 图们市| 天长市| 定安县| 延庆县| 额济纳旗| 三亚市| 铜陵市| 马龙县| 淮阳县| 和田市| 霍山县| 龙井市| 饶阳县| 苏州市| 郸城县| 神池县| 延吉市| 如东县| 钟祥市| 临城县| 榆社县| 安塞县|