在工作中,我有一种编程语言编码在数据库记录中。我试图在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