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:
- #-*-Coding: UTF-8 -*-
- When importing a win32clipboard as c # import package, if the package name is too long,
You can use as to create an alias.
- Import win32con as w # the above two packages are specifically for the windows platform. Note:
- Import re c. OpenClipboard () # Open the clipboard
- StrList = c. GetClipboardData (w. CF_TEXT). splitlines (1)
# Read the clipboard content to a character list
- C. EmptyClipboard () # Clear the clipboard
- 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.
- C. CloseClipboard () # Close the clipboard
The above is a detailed introduction to the Python input method.