我試圖做在Python中一個簡單的腳本,將打印十六進制值和增量值是這樣的:Python的迭代
char = 0
char2 = 0
def doublehex():
global char,char2
for x in range(255):
char = char + 1
a = str(chr(char)).encode("hex")
for p in range(255):
char2 = char2 + 1
b = str(chr(char2)).encode("hex")
c = a+" "+b
print "testing with:%s"%(c)
doublehex()
輸出:
testing with:01 01
testing with:01 02
testing with:01 03
[snip]
testing with:01 fd
testing with:01 fe
testing with:01 ff
Traceback (most recent call last):
File "test2.py", line 16, in doublehex
b = str(chr(char2)).encode("hex")
ValueError: chr() arg not in range(256)
其實我正在嘗試做的是:
01 01
01 02
[snip]
01 ff
02 01
02 02
依此類推,直到ff ff
。我的腳本有什麼問題?
而且似乎我不能嘗試:
00 01
00 02
我不知道爲什麼。
嘿,比我好:) – 2010-06-04 08:08:39