當前位置:首頁 » 編程語言 » python位元組

python位元組

發布時間: 2022-01-13 23:14:45

❶ 如果電腦里32位元組和64位元組的python都有,那麼默認用的是哪個

32位和64位吧?如果要編譯為EXE文件,建議用32位的。32位的編譯後可在32位和64位下運行,64位的編譯後只能在64位下運行。

❷ 請教各位,如何得到一個PYTHON變數的位元組大小

python獲得一個變數的名字的方法:
正常人:
items={
'tom':[1,2,3],
'jack':[4,5,6],
'alice':[7,8,9]
}
for x in items:
print "id of %s is %d" %(x,id(x))
變態:
tom = [1,2,3]
jack = [4,5,6]
alice = [7,8,9]
items = tom, jack, alice
for item in items:
for itemx,itemy in locals().items():
if item == itemy and itemx != 'item':
print itemx

❸ python 判斷位元組是二進制還是字元

1.說實話,沒看懂你的問題。
2.關於字元,建議你先去看看:
【整理】Python中字元編碼的總結和對比:Python 2.x的str和unicode vs Python 3.x的bytes和str
3.看完後,再回來,說清楚你想要做什麼。遇到什麼問題。
最好舉例說明。

(此處不給貼地址,請自己用google搜帖子標題,即可找到帖子地址)

❹ python發送位元組

沒有聽明白你在說什麼。在程序內部,是不存在「16」進制的。只有內存的存貯格式。比如字元串和整型,日期型等等。

所以你說的16進制應該就是字元串,你傳遞一次看看就知道了。

一般來講,只有特定的文件讀寫方法,才會要求你必須是「字元」才能讀寫。 其實一般的文件讀寫只要求是一個串,計算機里,所有東西可以看成串。特別是C語言里。更是這樣子。

所以你說的轉換可能不是將16進制轉成位元組。 而將16進制的編碼轉成整型的UNICODE,再做一個ENCODE,變成字元串。 也許你只缺少了一個ENCODE。

16進制給人閱讀的,在程序內部是不存在16進制的。

❺ Python3 位元組怎麼算

數字和漢字所佔的長度不一樣,所以用相同的格式不能對齊。

❻ 使用Python按位元組分割字元串

按行讀取之後按原文件編碼類型解碼,插入完後按UTF-8解碼寫入文件

以源文件為gbk為例,假設每5字元插入|

python2

withopen('target','w')asf:
forlineopen('source').readlines():
line=line.decode('gbk')
line='|'.join([line[i:min(i+5,len(line))]foriinrange(0,len(line),5)])
f.write(line.encode('utf-8'))

python3

withopen('target','w',encoding='utf-8')asf:
forlineopen('source',encoding='gbk').readlines():
line=line
line='|'.join([line[i:min(i+5,len(line))]foriinrange(0,len(line),5)])
f.write(line)

❼ Python如何檢測一個符號占幾個位元組(用的UTF-8)

print(len('a'.encode('utf-8')))

print(len('一'.encode('utf-8')))

❽ python int占幾個位元組

《深入理解計算機系統》這本書上面提到了在32位機器和64機器中int類型都佔用4個位元組。《The C Programming language》這本書,裡面有一句話是這樣的:Each compiler is free to choose appropriate sizes for its own hardware, subject only to the restriction that shorts and ints are at least 16bits, longs are at least 32bits, and short is no longer than int, which is no longer than long.意思大致是編譯器可以根據自身硬體來選擇合適的大小,但是需要滿足約束:short和int型至少為16位,long型至少為32位,並且short型長度不能超過int型,而int型不能超過long型。這即是說各個類型的變數長度是由編譯器來決定的,而當前主流的編譯器中一般是32位機器和64位機器中int型都是4個位元組(例如,GCC)。
相關推薦:《Python教程》
下面列舉在GCC編譯器下32位機器和64位機器各個類型變數所佔位元組數:
需要說明一下的是指針類型存儲的是所指向變數的地址,所以32位機器只需要32bit,而64位機器需要64bit。

❾ python位元組轉換

importstruct
struct.pack("i",200).encode('hex')
struct.pack("f",3.14).encode('hex')
'hello'.encode('hex')

struct.unpack('i','c8000000'.decode('hex'))[0]
round(struct.unpack('f','c3f54840'.decode('hex'))[0],5)
'68656c6c6f'.decode('hex')
'{%s}'%','.join([str(int(i,16))foriinre.findall(r'.{2}','68656c6c6f')])
''.join([hex(int(i))[2:]foriinre.findall(r'd+','{104,101,108,108,111}')])

Python 2.7.12 (default, Nov 22 2016, 17:23:24)

[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2

Type "right", "credits" or "license()" for more information.

>>> import struct

>>> struct.pack("f", 3.14).encode('hex')

'c3f54840'

>>> round(struct.unpack('f','c3f54840'.decode('hex'))[0],5)

3.14

>>> struct.pack("i", 200).encode('hex')

'c8000000'

>>> struct.unpack('i','c8000000'.decode('hex'))[0]

200

>>> '68656c6c6f'.decode('hex')

'hello'

>>> 'hello'.encode('hex')

'68656c6c6f'

>>> import re

>>> '{%s}' % ','.join([str(int(i,16)) for i in re.findall(r'.{2}','68656c6c6f')])

'{104,101,108,108,111}'

>>> ''.join([hex(int(i))[2:] for i in re.findall(r'd+','{104,101,108,108,111}')])

'68656c6c6f'

❿ python一個字元占幾個位元組

漢字字元在utf_b8編碼下佔三個位元組,在gbk 編碼下占兩個位元組。

熱點內容
好醫生連鎖店密碼多少 發布:2024-09-20 05:09:38 瀏覽:15
魔獸腳本代理 發布:2024-09-20 05:09:35 瀏覽:98
python登陸網頁 發布:2024-09-20 05:08:39 瀏覽:757
安卓qq飛車如何轉蘋果 發布:2024-09-20 04:54:30 瀏覽:178
存儲過程中in什麼意思 發布:2024-09-20 04:24:20 瀏覽:315
php顯示數據 發布:2024-09-20 03:48:38 瀏覽:501
源碼安裝軟體 發布:2024-09-20 03:44:31 瀏覽:354
入門編程游戲的書 發布:2024-09-20 03:31:26 瀏覽:236
e盒的演算法 發布:2024-09-20 03:30:52 瀏覽:144
win10登錄密碼如何修改登錄密碼 發布:2024-09-20 03:09:43 瀏覽:71