"Python" simple. cpp file creation is the init script--acmer private

Source: Internet
Author: User

Just in touch with Python today, in the spirit of practical use, wrote a script that automatically generates a. cpp file and initializes the header file as required.

Make sure that you have Python installed in your Linux and copy the following code into a file [FileMaker], right (chmod +x FileMaker)

Function:

1. FileMaker [file name], which is the generated file name. cpp

2. filemaker-e [A-z] generates all letters from A to the letters you enter. CPP

3, Filemaker-n [1-26] is generated from a beginning of the number of files you entered, uppercase increments

You can set the environment variable in the directory where the script is located, and you can use it directly later.

Vim ~/.profile

At the end add

Export path= "directory: $PATH"

Save exit

Source. Profile

Can

The code is as follows:

Note: The sixth line of Headfile is the directory where you want to initialize the header file

1 #!/usr/bin/python2 3 ImportSYS4 5Content = []6Headfile ="/home/kevince/documents/acm/head/acmhead.h" #The directory of the headfile7 8 #load file Head.h and save it with a list9 defloadcontent (filename):Tenf =open (filename) OneLines =F.readlines () A      forLineinchlines: - Content.append (line) -  the #Main function - defMain (): -Loadcontent (Headfile)#loadcontent -Arglen =Len (SYS.ARGV) +Flag = 1 -     ifArglen = = 2:#judge the lenth of Arg +f = open (Sys.argv[1] +'. cpp',"W") A          forIndex, ValinchEnumerate (content): at F.write (val) - f.close () - sys.exit () -     elifArglen = = 3: -         ifSYS.ARGV[1] = ='- N': -e = Int (sys.argv[2]) inE = e + ord ('A') -             ifE > Ord ('Z')orE < Ord ('A'): to                 Print "1-26 please!\n" + sys.exit () -         elifSYS.ARGV[1] = ='- e': theE = Ord (sys.argv[2]) *               ifE > Ord ('Z')orE < Ord ('A'): $                 Print "A- z please!\n"Panax Notoginseng sys.exit () -E = e + 1 the         Else: +Flag =0; A     Else: theFlag =0; +     ifFlag = =0: -         Print "\ n" $         Print "Iiacm-filemaker [fliename]\n" $         Print "or\n" -         Print "iiacm-filemaker-n |-e\n" -         Print "-N Number of files\n" the         Print "- e endplace of files\n" - sys.exit ()Wuyis = Ord ('A') the      forTinchRange (S, e): -f = open (Chr (t) +'. cpp',"W") Wu          forIndex, ValinchEnumerate (content): - F.write (val) About F.close $  -  - if __name__=='__main__': -Main ()

"Python" simple. cpp file creation is the init script--acmer private

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.