Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop cmdloop() from stripping white space from the input line in python

Tags:

python

My code looks something like this in short:

class myClass(cmd.Cmd):

  def do_myFunction(self, line):
    print line+'!'

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

When I use this on the command line and type a line with whitespace at the end, the cmdloop() readline seems to automatically strip them so instead of printing:

myline !

it prints:

myline!

Does anybody know a way around this? Thanks in advance!

like image 961
antares Avatar asked Sep 18 '13 16:09

antares


1 Answers

Copying the answer from the comments in order to remove this question from the "Unanswered" filter:

"It looks like overriding the parseline() method and doing essentially the same thing it does now but removing the calls to .strip() will fix it without needing to rewrite the entire module..."

~ answer courtesy of Wooble

like image 149
DreadPirateShawn Avatar answered Sep 23 '22 07:09

DreadPirateShawn