python 文件轉(zhuǎn)成16進(jìn)制數(shù)組的實例
更新時間:2018年07月09日 11:15:13 作者:xp5xp6
今天小編就為大家分享一篇python 文件轉(zhuǎn)成16進(jìn)制數(shù)組的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
如下所示:
#! /usr/bin/python2
# coding=utf-8
import numpy
import binascii
if __name__=='__main__':
#my_matrix = numpy.loadtxt(open("d:\\local.pcm", "rb"), delimiter=",", skiprows=0)
#print my_matrix
with open('d:\\local.pcm', 'rb') as f:
all = f.read()
with open('d:\\aa.txt', 'w') as f:
f.write("char buf[]={")
for d in all:
#e = "%02s," % hex(ord(d))
#print binascii.b2a_hex(d)
e = "0x%s," % binascii.b2a_hex(d)
#print e
f.write(e)
#L = f.tell()
#f.seek(L-1,0)
f.seek(-1, 2)
f.write("};")
'''
for i in all:
#print type(i),i,int('0x10', i)
x = "0x%s" % i
print type(x),x
b = binascii.b2a_hex(i)
c = "0x%s" % b
print b,type(b),c, type(c)
'''
以上這篇python 文件轉(zhuǎn)成16進(jìn)制數(shù)組的實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
解決運行django程序出錯問題 ''str''object has no attribute''_meta''
這篇文章主要介紹了解決運行django程序出錯問題 'str'object has no attribute'_meta',具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-07-07
python wav模塊獲取采樣率 采樣點聲道量化位數(shù)(實例代碼)
這篇文章主要介紹了python wav模塊獲取采樣率 采樣點聲道量化位數(shù),本文通過實例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下2020-01-01
Django使用mysqlclient服務(wù)連接并寫入數(shù)據(jù)庫的操作過程
這篇文章主要介紹了Django使用mysqlclient服務(wù)連接并寫入數(shù)據(jù)庫,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-07-07

