2017-08-18 6 views
0

Mac OSのPython 3.6でCmd.cmdフレームワークをしばらくテストした後、私は何をすべきか分からないという問題に気付きました。オートコンプリートが機能していないようです。動作するようには思えないPython3のcmd.CmdオートコンプリートがMac OSで動作しないのはなぜですか?

import cmd 

addresses = [ 
    '[email protected]', 
    '[email protected]', 
    '[email protected]', 
] 

class MyCmd(cmd.Cmd): 
    def do_send(self, line): 
     pass 

    def complete_send(self, text, line, start_index, end_index): 
     if text: 
      return [ 
       address for address in addresses 
       if address.startswith(text) 
      ] 
     else: 
      return addresses 


if __name__ == '__main__': 
    my_cmd = MyCmd() 
    my_cmd.cmdloop() 

が、それだけで空白スペース(通常のタブ)を追加します。私は、フォーラムで見つけ、簡単なコードでテスト。どんなworkaroud?

答えて

0

次の例>>>https://pymotw.com/2/cmd/のpython自動補完を参照してください。

以下は、あなたの変更されたコードです:

import cmd 

class MyCmd(cmd.Cmd): 


addresses = [ 
'[email protected]', 
'[email protected]', 
'[email protected]'] 

def do_send(self, line): 
    "Greet the person" 
    if line and line in self.addresses: 
     sending_to = 'Sending to, %s!' % line 
    elif line: 
     sending_to = "Send to, " + line + " ?" 
    else: 
     sending_to = '[email protected]' 
    print (sending_to) 

def complete_send(self, text, line, begidx, endidx): 
    if text: 
     completions = [ 
      address for address in self.addresses 
      if address.startswith(text) 
     ] 
    else: 
     completions = self.addresses[:] 

    return completions 

def do_EOF(self, line): 
    return True 

if __name__ == '__main__': 
    MyCmd().cmdloop() 

テストし、それが動作することを参照してください。幸運

+0

実際にはどちらも動作しません。私はマックにいるという事実とは何か? – Blaxou

関連する問題