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. Docker 容器健康檢查機(jī)制2. CSS3實(shí)現(xiàn)動(dòng)態(tài)翻牌效果 仿百度貼吧3D翻牌一次動(dòng)畫特效3. ASP.NET MVC使用正則表達(dá)式驗(yàn)證手機(jī)號(hào)碼4. PHP接收json并將接收數(shù)據(jù)插入數(shù)據(jù)庫(kù)5. python datetime時(shí)間格式的相互轉(zhuǎn)換問(wèn)題6. 基于python實(shí)現(xiàn)數(shù)組格式參數(shù)加密計(jì)算7. Rollup 簡(jiǎn)易入門示例教程8. php判斷一個(gè)請(qǐng)求是ajax請(qǐng)求還是普通請(qǐng)求的方法9. Python requests庫(kù)參數(shù)提交的注意事項(xiàng)總結(jié)10. python 爬取京東指定商品評(píng)論并進(jìn)行情感分析
