python實現(xiàn)在內(nèi)存中讀寫str和二進制數(shù)據(jù)代碼
我就廢話不多說了,還是直接看代碼吧!
# 利用python在內(nèi)存中讀寫str和二進制數(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’
補充知識:python二進制轉(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實現(xiàn)在內(nèi)存中讀寫str和二進制數(shù)據(jù)代碼就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持好吧啦網(wǎng)。
相關文章:
1. 爬取今日頭條Ajax請求2. 詳解JSP 內(nèi)置對象request常見用法3. JavaScrip簡單數(shù)據(jù)類型隱式轉(zhuǎn)換的實現(xiàn)4. HTML DOM setInterval和clearInterval方法案例詳解5. laravel ajax curd 搜索登錄判斷功能的實現(xiàn)6. ASP.NET Core按用戶等級授權的方法7. webpack高級配置與優(yōu)化詳解8. HTML <!DOCTYPE> 標簽9. ASP動態(tài)網(wǎng)頁制作技術經(jīng)驗分享10. JS中map和parseInt的用法詳解
