How to quickly generate annotation documents in Python
How to quickly generate annotation documents with python
Today I will tell you a simple small detail that you only need to pay attention to, you can easily generate annotation documents, and you can also check whether the reference names of the class methods we wrote are repeated or have problems, etc. When you look at the documentation written by other professional experts, you will be envious. Don’t worry, we can let Python generate basically satisfactory documentation for us. Firstly, it can improve the overall readability of the code. Secondly, we can see the overall structure of the code. It is also clearer, which can save a lot of trouble during handover. When other colleagues take over your work, they will not ask you line by line what this is and what it is, because the comments have been expressed very intuitively, and in the integration Sometimes it can be used as a description document to give brief instructions to customers (mainly for your BOSS). Then let’s get to the point of how to implement it. See my simple code format below. Note that the comment place and function name and class name are all related to __all__.
#!/usr/bin/env python # -*-coding:utf-8 -*- ''' 文档快速生成注释的方法介绍,首先我们要用到__all__属性 在Py中使用为导出__all__中的所有类、函数、变量成员等 在模块使用__all__属性可避免相互引用时命名冲突 ''' __all__ = ['Login', 'check', 'Shop', 'upDateIt', 'findIt', 'deleteIt', 'createIt'] class Login: ''' 测试注释一可以写上此类的作用说明等 例如此方法用来写登录 ''' def __init__(self): ''' 初始化你要的参数说明 那么登录可能要用到 用户名username 密码password ''' pass def check(self): ''' 协商你要实现的功能说明 功能也有很多例如验证 判断语句,验证码之类的 ''' pass class Shop: ''' 商品类所包含的属性及方法 update改/更新 find查找 delete删除 create添加 ''' def __init__(self): ''' 初始化商品的价格、日期、分类等 ''' pass def upDateIt(self): ''' 用来更新商品信息 ''' pass def findIt(self): ''' 查找商品信息 ''' pass def deleteIt(self): ''' 删除过期下架商品信息 ''' pass def createIt(self): ''' 创建新商品及上架信息 ''' pass if __name__=="__main__": import pythonzhushi print help(pythonzhushi)
I would like to emphasize that the name of py must be the same as the name of the py you are currently working on (the name of the py I created here is pythonzhushi, and the final import is also this name), because in the following test, the import imports itself, so , the import name, Help (name) and your file name must be consistent. In order to be more intuitive, please look at the picture below:
Of course, you can also import from other files. Here we use the common import method of Python from which directory to import what files to import pythonzhushi
Of course I still use pictures here. Show the following:
Is it clear at a glance? In this way, we can also import the annotation documents we need to do. The help method is to help us view a simple help document for the classes and functions contained in this file, similar to the readme A description of the document. Finally, let’s take a look at the masking effect:
Is it possible to simply print out the description document of our program? In the following steps, you can directly create a text and paste this over to complete a readme document description. After testing A few points to note are that if you want to write a comment like #, don't write it inside the def. It should be written above it, similar to the decorator. On the contrary, don't write the three quotation marks ''' outside the def. This will have no display effect. . Everyone, hurry up and try it. thanks for watching. .

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

Docker uses Linux kernel features to provide an efficient and isolated application running environment. Its working principle is as follows: 1. The mirror is used as a read-only template, which contains everything you need to run the application; 2. The Union File System (UnionFS) stacks multiple file systems, only storing the differences, saving space and speeding up; 3. The daemon manages the mirrors and containers, and the client uses them for interaction; 4. Namespaces and cgroups implement container isolation and resource limitations; 5. Multiple network modes support container interconnection. Only by understanding these core concepts can you better utilize Docker.

Python excels in automation, scripting, and task management. 1) Automation: File backup is realized through standard libraries such as os and shutil. 2) Script writing: Use the psutil library to monitor system resources. 3) Task management: Use the schedule library to schedule tasks. Python's ease of use and rich library support makes it the preferred tool in these areas.

In VS Code, you can run the program in the terminal through the following steps: Prepare the code and open the integrated terminal to ensure that the code directory is consistent with the terminal working directory. Select the run command according to the programming language (such as Python's python your_file_name.py) to check whether it runs successfully and resolve errors. Use the debugger to improve debugging efficiency.

VS Code is the full name Visual Studio Code, which is a free and open source cross-platform code editor and development environment developed by Microsoft. It supports a wide range of programming languages and provides syntax highlighting, code automatic completion, code snippets and smart prompts to improve development efficiency. Through a rich extension ecosystem, users can add extensions to specific needs and languages, such as debuggers, code formatting tools, and Git integrations. VS Code also includes an intuitive debugger that helps quickly find and resolve bugs in your code.

VS Code can be used to write Python and provides many features that make it an ideal tool for developing Python applications. It allows users to: install Python extensions to get functions such as code completion, syntax highlighting, and debugging. Use the debugger to track code step by step, find and fix errors. Integrate Git for version control. Use code formatting tools to maintain code consistency. Use the Linting tool to spot potential problems ahead of time.

VS Code extensions pose malicious risks, such as hiding malicious code, exploiting vulnerabilities, and masturbating as legitimate extensions. Methods to identify malicious extensions include: checking publishers, reading comments, checking code, and installing with caution. Security measures also include: security awareness, good habits, regular updates and antivirus software.
