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

How to make self-made Python functions to help query gadgets

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

Share

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

Today, I will talk to you about how to make Python functions to help query gadgets, many people may not understand, in order to make you better understand, the editor summarized the following, I hope you can get something according to this article.

Python's built-in documentation function is very good, giving me a refreshing feeling. If you do "line programming" programming in CMD, you can query the function anytime and anywhere, which is very convenient. For example, when learning modules such as list, tuple, dict, str, os, sys, etc., we can learn those processing functions quickly and comprehensively by using Python's own documentation. Therefore, this self-contained documentation function can bring great convenience to scholars, and it is better to carry out a short development.

However, when you leave CMD and want to use IDLE or software such as Komodo Edit for "segmented programming", you are a little stretched. For example, the wx library is so large that there are as many help files as 10MB. If you open it in CMD, you can think about how long it will take you to see the help you want. After a large-scale familiarity with the various API of Python, you will find that this is not as easy to use as you might think. Constantly press any key to turn the page, at the same time, the page can hold a limited number of pages. So it shows a lot of inconvenience.

There are probably two ways to solve this problem.

Use the Module Docs tool

This tool is a method that comes with Python GUI IDLE to query help files. Inside, you can use the form of a web page and the local function of the machine to provide a query method that simulates the online. It can open a web page, which can show all the functions, and with a standard classification, relatively clear, but still not convenient to use, after all, there is no search function. If you save the link to the found web content, it cannot be used continuously. So this has a big problem, at the same time, the generated web page file is huge, the memory is too small will bring pressure to the system. So this method is not a very convenient method to use.

Second, develop your own tools.

In fact, I don't want to develop my own tools, because after all, it takes time, less or more in a few days or weeks, and it puts a lot of pressure on my heart. after all, it takes a lot of distractions to do it. I looked for a long time on the Internet, but could not find it. For wx, I found an English document of wxPython API, which is not very clear and vague. It directly lists the functions and specific parameters, and how to use them is rarely mentioned, and the various style of many controls are not listed in detail. So it is very difficult to use, if the name is forgotten, you can also check the complete words and a detailed list of parameters. Other functions are rarely involved at all.

In view of this, I decided to make my own gadget and spend less system cost to easily query the functions of various functions and modules. Only one working version is given here. Open source code for everyone, code style and control design for beginners to imitate. The master is willing to criticize me, I am all ears. The subsequent version will also be released here, which may be packaged first and then released, and now this is the source code file, as we all know, the Python source code file can be executed by double-click.

# coding=utf-8 # function introduction: at first, this software is only used for querying the usage of modules and functions to quickly display # extension: you can save the successful results of the query locally, # save the results of some of the functions in Chinese after annotating them in Chinese # to put the saved keywords in the list on the right # depth extension: save the results using the database And provide the API from Tkinter import * from StringIO import StringIO from tkSimpleDialog import * import sys import Pmw import ConfigParser import os import wx class Finder (Frame): def OnFind (self): # execute And get the result info = self.inputStr.get () if len (info) = = 0: return True buff = StringIO () temp = sys.stdout # Save the standard Imax O stream sys.stdout = buff # redirect the standard Imax O stream to the buff object self.text.delete (1.0) END) try: fmt = 'help (' + info+') 'result = eval (fmt) self.text.insert Buff.getvalue () self.savebtn.config (state=NORMAL) except: try: _ _ import__ (info) fmt = 'help (' + self.inputStr.get () +') 'result = eval (fmt) self.text.insert Buff.getvalue () except: self.text.insert (1.0, "ERROR.") Sys.stdout = temp # restore the standard buff.getvaue O stream buff.getvaue () self.helpbtn.config (state=NORMAL) def save (self): # search, save if not found, use the ini file Save data # Save original tofind = self.inputStr.get () if len (tofind) = 0: return filename='s_'+tofind+'.ini' fout = open (filename,'w') fout.write (self.text.get END) .encode ('utf-8') fout.close () self.items.append (tofind) self.items.sort () self.config.add_section (tofind) self.config.write (open (' data.ini',')) nindex = self.items.index (tofind) self.box.delete (0 END) self.box.insert (0, * self.items) self.box.see (nindex) self.box.selection_set (nindex) self.savebtn.config (state=DISABLED) def saveas (self): # Save and modify index = self.box.curselection () if index

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