2017-01-11 99 views
0

在GitHub上,我偶然發現了這個頁面(https://github.com/mbedmicro/pyOCD),它有助於使用mbed板。然而,當我看着他們的Hello World Example(下面)時,我真的很困惑。它使用了極其奇怪的Python語法(因編譯器拋出錯誤而無效)。奇怪的Python語法?

這就是:

from pyOCD.board import MbedBoard 

import logging 
logging.basicConfig(level=logging.INFO) 

board = MbedBoard.chooseBoard() 

target = board.target 
flash = board.flash 
target.resume() 
target.halt() 

print "pc: 0x%X" % target.readCoreRegister("pc") 
    pc: 0xA64 

target.step() 
print "pc: 0x%X" % target.readCoreRegister("pc") 
    pc: 0xA30 

target.step() 
print "pc: 0x%X" % target.readCoreRegister("pc") 
    pc: 0xA32 

flash.flashBinary("binaries/l1_lpc1768.bin") 
print "pc: 0x%X" % target.readCoreRegister("pc") 
    pc: 0x10000000 

target.reset() 
target.halt() 
print "pc: 0x%X" % target.readCoreRegister("pc") 
    pc: 0xAAC 

board.uninit() 

我的問題是出現散落翻過代碼中的「pc: 0xAAC」線。這是一些特殊類型的編碼嗎?它不起作用,所以有人請指出,作者試圖得到什麼?

謝謝

+5

它們嵌入在輸出到文件:

他們可以已讓這些線路的意見,當然,很容易使例子再次可運行使這個更清楚。 –

+1

多煩人。那些「pc:0xAAC」行應該已經寫成註釋,以便代碼可以運行。 –

+0

該示例的佈局非常不幸。我建議你讓作者通過[打開問題](https://github.com/mbedmicro/pyOCD/issues)或提交拉取請求來修復它。 – hansaplast

回答

5

這是一個例子,他們包括在文本中預期輸出

所以行

print "pc: 0x%X" % target.readCoreRegister("pc") 

預計將打印出類似這樣

pc: 0xA64 

所以,不,這不是有效的Python代碼,如果你想自己運行的代碼應忽略這些行。

print "pc: 0x%X" % target.readCoreRegister("pc") 
# pc: 0xA64 
+0

..或者可以使用常用標記來說明哪些行是代碼並輸出哪些代碼, '>>> print「...」' – hansaplast

+0

我打開了一篇關於文檔的PR來澄清這一點:https://github.com/mbedmicro/pyOCD/pull/273 –