python實(shí)現(xiàn)在內(nèi)存中讀寫str和二進(jìn)制數(shù)據(jù)代碼
我就廢話不多說(shuō)了,還是直接看代碼吧!
# 利用python在內(nèi)存中讀寫str和二進(jìn)制數(shù)據(jù)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’
補(bǔ)充知識(shí):python二進(jìn)制轉(zhuǎn)到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實(shí)現(xiàn)在內(nèi)存中讀寫str和二進(jìn)制數(shù)據(jù)代碼就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. asp讀取xml文件和記數(shù)2. IDEA中 Getter、Setter 注解不起作用的問(wèn)題如何解決3. Android CountDownTimer案例總結(jié)4. 簡(jiǎn)體中文轉(zhuǎn)換為繁體中文的PHP函數(shù)5. Python 中如何使用 virtualenv 管理虛擬環(huán)境6. 多個(gè)SpringBoot項(xiàng)目采用redis實(shí)現(xiàn)Session共享功能7. python利用opencv實(shí)現(xiàn)顏色檢測(cè)8. CSS自定義滾動(dòng)條樣式案例詳解9. 每日六道java新手入門面試題,通往自由的道路第二天10. PHP實(shí)現(xiàn)基本留言板功能原理與步驟詳解
