Python input methods

Source: Internet
Author: User

The Python input method is a concern of many people. In fact, there are three most practical input methods in practice. Next, let's take a look at the Python input method. We hope that everyone will gain some benefits. Only in this way can we better promote it.

1. File Method

Save the copied code as a text file, read it by the program, remove the row number, and write it back to the file. This method is the most inconvenient. you can calculate how many mouse clicks you need ...... So I didn't implement it. For Python file operations, you can search for a lot of information on the Internet.

  • Python if statement source code analysis
  • Three important steps of Python logical operations
  • Operations on the editor in the Python getting started tutorial
  • How to apply a Python Boolean expression
  • A detailed introduction to the Chinese full guide to Python

2. Window Mode

Paste the copied code into the text box of a form, click the button to remove the line number, and then copy the processed code from the text box. This is a common practice. I used wxPython and PyQt4 to implement this function. As GUI programming is a complicated problem, I will not elaborate on it and I will try again later.

3. Clipboard Mode

Copy the code to the clipboard, start the row number processing program, directly process the text in the clipboard, and then copy it to other places. This is the most convenient method, and the amount of code is very small because there is no need to build a GUI. See below:

 
 
  1. #-*-Coding: UTF-8 -*-
  2. When importing a win32clipboard as c # import package, if the package name is too long,
    You can use as to create an alias.
  3. Import win32con as w # the above two packages are specifically for the windows platform. Note:
  4. Import re c. OpenClipboard () # Open the clipboard
  5. StrList = c. GetClipboardData (w. CF_TEXT). splitlines (1)
    # Read the clipboard content to a character list
  6. C. EmptyClipboard () # Clear the clipboard
  7. C. SetClipboardData (w. CF_TEXT, ''. join (map (lambda x: re. compile \
    (R' \ D * \ d + \ s? [. |: | \] | \)]? \ S? '). Sub ('', x, count = 1), strList )))
    # Write the character after the row number to the clipboard. Code 3 is used here.
  8. C. CloseClipboard () # Close the clipboard

The above is a detailed introduction to the Python input method.
 

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.