Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the specific ways to implement Python input?

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

In this issue, the editor will bring you about the specific ways to achieve Python input. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.

Python input mode is a problem that many people are concerned about. In fact, there are three most practical input methods in practice.

1. File mode

Save the copied code as a text file, then read it with the program, remove the line number and write it back to the file. This method should be said to be the most inconvenient, you can calculate how many mouse clicks you need. Trouble, so I didn't realize it. About the Python file operation content, there are a lot of information on the Internet, you can search it.

2. Window mode

Paste the copied code into the text box of a form, then click the button to remove the line number, and then copy the processed code from the text box. This is a relatively conventional practice, I use wxPython and PyQt4 to achieve this function, because GUI programming is a more complex problem, I will not expand in detail, I will have time to write later.

3. Clipboard mode

After copying the code to the clipboard, start the processing line number program, process the text in the clipboard directly, and then copy it somewhere else. This is the most convenient approach, and since you don't have to build GUI, the amount of code will be small. See below:

#-*-coding: utf-8-*-

When import win32clipboard as c # import package, if the package name is too long

You can use an alias for as.

The above two packages of import win32con as w # are specific to the windows platform, please note

Import re c.OpenClipboard () # Open the clipboard

StrList = c.GetClipboardData (w.CF_TEXT) .splitlines (1)

# read the clipboard contents to a character list

C.EmptyClipboard () # empty the clipboard

C.SetClipboardData (w.CF_TEXT,''.join (map (lambda x:re.compile\)

(r'\ D*\ d +\ s? [. |: |\] |\)]?\ skeeper') .sub ('', xPowercount = 1), strList)

# write the characters after the missing line number back to the clipboard, code 3 is used here

C.CloseClipboard () # closes the clipboard

The above is the editor for you to share the specific implementation of Python input, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report