python automated headers 自动生成格式化 注释文件 docstrings

本文介绍如何使用gvim和Eclipse PyDev为C/C++及Python文件自动创建标准化的文件头注释模板,通过简单的配置即可在新建文件时自动生成包含作者、日期等信息的文件头。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

方法一:gvim

http://stackoverflow.com/questions/6201302/how-to-have-automated-headers-for-python-files
https://sites.google.com/site/bcgeopython/examples/eclipse-pydev/pydev—creating-automated-headers-in-eclipse

template:
/*******************************************************************
* @file
*
* @date
* @author John Doe
* @email jdoe@yourcompany.com
*
* @brief
*
* @detail
*
*******************************************************************/、

在_vimrc中配置
” Reads the template file replacing the tags by the actual
” information and insert the result at the beginning of the buffer. At
” the end, creates two blank lines at the end of the file and
” position the cursor at the first one.
function! s:insert_description()
let template = $HOME . “/.vim/template/cpp.template”
let file_name = expand(“%:t”) ” Get file name without path
let date = strftime(“%Y”) ” Get the current year in format YYYY
let i = 0
for line in readfile(template)
let line = substitute(line, “”, file_name, “ge”)
let line = substitute(line, “”, date, “ge”)
call append(i, line)
let i += 1
endfor
execute “normal! Go\k”
endfunction
autocmd BufNewFile *.{c++,cpp,cc,c,h,hpp} call insert_description()

方法二:Eclipse pydev

使用Eclipse 中的pydev 更容易生成
https://sites.google.com/site/bcgeopython/examples/eclipse-pydev/pydev—creating-automated-headers-in-eclipse

Search this site
Pages / Detailed How to’s‎ > ‎Eclipse / PyDev‎ > ‎
Eclipse / Pydev feature: Automated Headers in Eclipse
Introduction

When creating python scripts it is always a good idea to include a header with various bits and pieces of information about a script. Often when it comes time to writing a script deadlines and stress prevent the creation of adequate / standardized header information. This article will show you how you can use eclipse to create a header template for you with minimal effort.

Configuring Eclipse to Add Headers

Go to The pulldown menu and select Window->Preferences. The following form should appear.

On the left hand side of the form you should see a bunch of options with + boxes next to them. Find PyDev, then click on Code Completion->Templates. You should now see a dialog similar to the one show below.

Now choose New… You will be presented with a dialog similar to the one show below. Fill in each of the boxes with the following information:

Name: header

Description: Automatically creates a header template for you.

Pattern: (cut and paste the following into pattern)

”’

Author:        
Purpose:       
Date:          
Arguments:     
Outputs:      
Dependencies: 

History:      
--------------------------------------------------------------
Date: 
Author: 
Modification: 
--------------------------------------------------------------

”’

Using The Header Template

You should now be able to easily use your header tempate. Now whenever you create a new file, simply type the word “header” and then press ctrl and spacebar at the same time and your header template should appear. Now all you need to do is fill it out.

Once the initial code is created and you now want to either add new features, or modify the code somehow, fill in unique a history event.

Docstrings

http://www.pydev.org/manual_adv_editor_prefs.html

With Ctrl+1 when over a function line, you can create the docstring automatically (and these preferences are used to determine what’s the result of doing so)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值