Python implements sample code that automatically adds script header information _python

Source: Internet
Author: User

Objective

Each person writes a script in a different format, some will indicate the script itself some information, and some of the point, this in the small team in fact nothing, basic others do you also know, but if put to the big team is more trouble, because as the number of increase, the script exponential growth, if everyone's style is not unified, In the end there will be a very big disadvantage, so when the number of team growth, there must be a set of standards to form a unified coding rules, so even without looking at the actual implementation of the script, but also know what the function of the script.

The script we share today is a script that automatically adds annotation information, including the script name, author, time, description, script usage, language version, notes, and so on, and here's the sample code

#!/usr/bin/env python from Os.path import exists to time import strftime import os title = Raw_input ("Enter a Tit Le for your script: ") title = title + '. Py ' title = Title.lower () title = Title.replace (', ' _ ') if exists (title
  ): print "\na script with this name already exists." Exit (1) descrpt = Raw_input ("Enter a description:") name = Raw_input ("Enter your Name:") ver = raw_input ("Enter the VE 
 
Rsion number: ") div = ' ======================================= ' filename = open (title, ' W ') date = strftime ("%y%m%d ") Filename.write (' #!/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# ' + div * 2 + ' \ n ') filename.write (' \ n ') filename.wRite (' \ n ') filename.close () Os.system ("clear") Os.system ("Vim +12" + title) exit () 

The script does not do too much explanation, basically is obtains the information, then writes in a file, other does not have the nonsense, this script is simple enough, we most later looked the result which produces:

#!/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

If you think about it, if you have this basic information in front of each script, it looks a lot clearer, and hopefully this script will give you some help, of course, if you have any questions you can communicate. Thank you for your support to the cloud-dwelling community.

Related Article

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.