2

[Python] Concatenate JavaScript Files

 2 years ago
source link: http://siongui.github.io/2016/02/25/python-concatenate-javascript-files/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

[Python] Concatenate JavaScript Files

February 25, 2016

Concatenate JavaScript files via Python script.

#!/usr/bin/env python
# -*- coding: utf-8 -*- #

import os

def concatJS(dirpath):
    combinedJS = ""
    for filename in os.listdir(dirpath):
        if filename.endswith(".js"):
            filepath = os.path.join(dirpath, filename)
            print("combining " + filepath + " ...")
            with open(filepath, "r") as f:
                combinedJS += f.read()

    return combinedJS

if __name__ == "__main__":
    print(concatJS("."))

Tested on: Ubuntu Linux 15.10, Python 2.7.10.


References:

[1]python list file in directory


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK