python - Why is Python3's cmd.Cmd autocomplete not working on Mac OS? -
after testing while cmd.cmd framework in python 3.6 on mac os, noticed problem don't know about. autocomplete doesn't seem work. tested simple code found on forum :
import cmd addresses = [ 'here@blubb.com', 'foo@bar.com', 'whatever@wherever.org', ] class mycmd(cmd.cmd): def do_send(self, line): pass def complete_send(self, text, line, start_index, end_index): if text: return [ address address in addresses if address.startswith(text) ] else: return addresses if __name__ == '__main__': my_cmd = mycmd() my_cmd.cmdloop()
it doesn't seem work, adds blank space (normal tab). workaroud ?
please see following examples >>> https://pymotw.com/2/cmd/ python autocompletion.
below modified code:
import cmd class mycmd(cmd.cmd): addresses = [ 'here@blubb.com', 'foo@bar.com', 'whatever@wherever.org'] def do_send(self, line): "greet person" if line , line in self.addresses: sending_to = 'sending to, %s!' % line elif line: sending_to = "send to, " + line + " ?" else: sending_to = 'noreply@example.com' print (sending_to) def complete_send(self, text, line, begidx, endidx): if text: completions = [ address 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()
test , see works. luck
Comments
Post a Comment