2013-08-21 36 views
0

我有一个程序,扫描输入文本寻找一个命令。一个命令位于大写字母中,并由<>符号包围。python函数不返回期望的字符串

此程序的一部分包括用于扫描前方的下一个命令

def nextCommand(command): 
    lar = command.find("<LAR>") 
    #...etc (stripped out variable defs used in statements below) 
    if lar != -1 and lar > sma or lar > med or lar > bar or lar > fba or lar > fee or lar > lef or lar > rig or lar > cen or lar > end: 
     print "nextCommand - lar:" + str(lar) 
     return str("<LAR>") 
    if sma != -1 and sma > lar or sma > med or sma > bar or sma > fba or sma > fee or sma > lef or sma > rig or sma > cen or sma > end: 
     print "nextCommandsma:" + str(sma) 
     return str("<SMA>") 
     #stripped out more checks 
    else: 
     return str("") 

将调用此方法在主程序

print_text = "" 
      if str(nextCommand(input_string)) != "": 
        next_command = str(nextCommand(input_string)) 
        print "value recieved from nextCommand() is: " + str(nextCommand) 

函数。如果我输入 123 SMA 456 LAR 789 代替看到SM>我看到:(拿出<符号作为s/o认为其攻击的一部分) “从nextCommand()收到的值是:

function nextCommand at <0xb74ce1ec> 

我做错了什么?

+2

为什么'str(“”)'? '“”'是一个字符串。 – Matthias

+0

它最初并不是,但试图调试时在周围嗅探错误 –

回答

4

您实际上已经打印了函数的表示形式。注意:

nextCommand # This references the function 

和:

nextCommand() # This calls the function 

我想你的意思是把next_command这里,而不是nextCommand

print "value recieved from nextCommand() is: " + str(nextCommand) 

应该是:

print "value recieved from nextCommand() is: " + next_command 
+0

糟糕(doh)......谢谢:) –

+0

@ICTTeacher不客气:)。不要忘记[接受答案](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work):) – TerryA