Python constructs a command-line interface using the CMD module

Source: Internet
Author: User

Recently done testing tools, really lazy to engage in GUI, and then realize that Python comes with a module called CMD, with the discovery is simply a lifesaver. The CMD class in the default CMD module uses Rawinput to handle the work of prompt display and input information acquisition, but in certain cases there is a problem:

When the interactive thread waits for the user to enter instructions, if you want some other background thread to be able to print the information to the foreground display ...

Printing is printed, of course, but as soon as you start typing in the new instructions, the print information is erased, leaving only the prompt and the new input. If you want to see something in real time ...

Repeatedly try and read the CMD module source code later found that the Cmd class at the time of instantiation, the default will have a Use_rawinput property is 1, if the overload __init__ () when it is set to 0, Then the prompt and input will be handled by ReadLine (of course, if you play this hand on windows, you'd better put the pyreadline on, Windows I didn't get the GNU ReadLine, I don't know if it was done), Then the printing information is erased and the problem is solved.

Python constructs a command-line interface using the CMD module

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.