Convert source code to PDF in Python

Source: Internet
Author: User

1 ImportOS2 ImportSYS3 4 deffind_file (Root_dir, type):5Dirs_pool =[Root_dir]6Dest_pool = []7 8     defscan_dir (directory):9Entries =os.walk (directory)Ten          forRoot, dirs, filesinchEntries: OneDirs_pool.extend ([Os.path.join (Root, Dir_entry) forDir_entryinchdirs]) A              forFile_entryinchFiles: -                 ifTypeinchSTR (file_entry) [-len (type):]: -Dest_pool.append ("'. Join (Os.path.join (root, File_entry ))) the  -      whileDirs_pool: - Scan_dir (Dirs_pool.pop ()) -     returnDest_pool +  - defgen_ps (Root_dir, type): +Vim_cmd ='Vim-me-e-C ": hardcopy >%.ps"-C ": Q"' APs2pdf_cmd ='ps2pdf {filename}.ps {filename}.pdf' atDests =find_file (Root_dir, type) -     if  notdests: -         return -     Print 'found these source code files:' -      forDestinchdests: -         Printdest in     Print 'begin generate PS files!' -      forDestinchdests: toCommand ="'. Join ([Vim_cmd, dest]) +         PrintCommand - os.system (command) the      forDestinchdests: *Command = Ps2pdf_cmd.format (filename=dest) $         PrintCommandPanax Notoginseng os.system (command) -  the if __name__=='__main__': +     ifLen (sys.argv) = = 3: AGen_ps (sys.argv[1], sys.argv[2]) the     Else: +         Print 'usage:python code2pdf.py Directory filetype\n'  -               'such As:python code2pdf.py/home/bruce/python. PY'

Convert source code to PDF in Python

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.