在我開始之前,讓我只說我對編程非常陌生,所以請不要殺了我。Python:For循環不會完成
作爲一個練習,我編寫了一個腳本,該腳本應該從txt獲取十六進制數字的列表,將它們轉換爲十進制並將它們寫入另一個文件。這是我想出了:
hexdata = open(raw_input("Sourcefile:")).read().split(',')
dec_data = []
print hexdata
x = -1
for i in hexdata:
next_one = hexdata.pop(x+1)
decimal = int(next_one, 16)
print "Converting: ", next_one, "Converted:", decimal
dec_data.append(decimal)
print dec_data
target = open(raw_input("Targetfile: "), 'w')
for n in dec_data:
output = str(n)
target.write(output)
target.write(",")
當我運行它完成內部消除錯誤,但它只是轉換和從我的資源文件中寫入前30個數字,而忽略所有其他的腳本,即使它們被裝入'hexdata'列表。我已經嘗試了幾個變化,但它從來沒有與所有的數字(48)。我究竟做錯了什麼?
dec_data中出現了多少個? –
'hexdata.pop(x + 1)'似乎很奇怪...... –