在工作中,我有一種編程語言編碼在數據庫記錄中。我試圖在python中編寫一個打印函數來顯示記錄包含的內容。Python代碼似乎無序執行
這是我遇到的麻煩的代碼:
# Un-indent the block if necessary.
if func_option[row.FRML_FUNC_OPTN] in ['Endif', 'Else']:
self.indent = self.indent - 1
# if this is a new line, indent it.
if len(self.formulatext) <> 0 and self.formulatext[len(self.formulatext) - 1] == '\n':
for i in range(1,self.indent):
rowtext = ' ' + rowtext
# increase indent for 'then', 'else'
if func_option[row.FRML_FUNC_OPTN] in ['Then', 'Else']:
self.indent = self.indent + 1
當row.FRML ____ FUNC____OPTN等於「別人的,我期待它首先取消縮進,然後再次縮進,使「其他」在較低的縮進級別打印,然後代碼的其餘部分在內。這實際上是縮進我得到的類型:
IfThen
IfThen
Else
EndifComment
IfThen
Endif
IfThen
Else
Endif
Else
Endif
正如你可以看到「別人的比的if/endif仍然縮進更高。任何想法,爲什麼會發生這種情況?
我曾嘗試用灑調試語句,其結果是代碼:
row: Else
row.FRML_FUNC_OPTN is : Elsedecrementing indent
row.FRML_FUNC_OPTN is : Elseincrementing indent
這意味着縮進改變,如果確實被輸入的...
把一些日誌記錄在你的代碼來跟蹤它。例如,你確定func_option是'Else'嗎?也許這是'其他',或者其他一些排列?你可能根本不會觸及unindent/indent代碼。 – 2009-09-25 11:16:07
我確實在調試語句中添加了代碼。 row:否則 row.FRML_FUNC_OPTN是:其他的縮進縮進 row.FRML_FUNC_OPTN是:Else增量縮進 – Alterlife 2009-09-25 11:20:46
rowtext是否已經在開始處包含空格? – 2009-09-25 11:26:13