Python implementation automatically adds script header information

Source: Internet
Author: User
Preface

Each person writes the script the format will be different, some will indicate the script itself some information, some is straight to the point, this in small team in fact nothing, basic others do what you also know, but if put to big team is more troublesome, because as the number of increase, the script exponential growth, if everyone style is not unified, In the end it will be a very big disadvantage, so when the number of team growth, we must have a set of standards to form a unified code rules, so that even if you do not see the script implementation, but also know what the function of the script.

A script we share today is a script that automatically adds comment information, including the script name, author, time, description, script usage, language version, comments, and so on, as shown in the sample code

#!/usr/bin/env python from Os.path import existsfrom time import strftimeimport os title = Raw_input ("Enter a title for y Our script: ") title = title + '. Py ' title = Title.lower () title = Title.replace (', ' _ ') if exists (title): print" \na s  Cript with this name already exists. " Exit (1) descrpt = Raw_input ("Enter a description:") name = Raw_input ("Enter your Name:") ver = raw_input ("Enter the Versio N number: ") p = ' ======================================= ' filename = open (title, ' W ') date = strftime ("%y%m%d ") FILENAME.W Rite (' #!/usr/bin/python ') filename.write (' \n#title\t\t\t: ' + title ') Filename.write (' \n#description\t\t: ' + descrpt) Filename.write (' \n#author\t\t\t: ' + name ') filename.write (' \n#date\t\t\t: ' + Date ') Filename.write (' \n#version\t\t: ' + ver) filename.write (' \n#usage\t\t\t: ' + ' python ' + title) Filename.write (' \n#notes\t\t\t: ') filename.write (' \n#python _version\t\t:2.6.6 ') filename.write (' \n# ' + p * 2 + ' \ n ') filename.write (' \ n ') filename.write (' \ n ') Filename.close () Os.system ("Clear") Os.system (" Vim +12 "+ title) exit () 

The script does not explain too much, basically is to get information, and then write to a file, the rest of the nonsense, the script is simple enough, we look at the results of the generation:

#!/usr/bin/python#title:         test4.py#description      : I am Test script#author         :p Ython technology #date          : 20160902# Version        : 0.1#usage         :p ython test4.py#notes         : #python_version     : 2.6.6#============================= =================================================

Summarize

Think about it, if each script has these basic information, it will look a lot clearer, and finally hope that the script to give you some help, of course, if there are any questions can be exchanged message. Thank you for your support of topic.alibabacloud.com.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.