#!/usr/bin/python3
# -*- coding:utf8 -*-
import os
def readfile(path):
# 存放路径
deposit_path = os.path.abspath('.') + '/files'
if not os.path.isdir(deposit_path):
os.mkdir(deposit_path)
with open('/Users/liangxiangdong/Desktop/raw.js', 'r') as e:
list1 = e.readlines()
for i in range(len(list1)):
data_write_file(list1[i], deposit_path)
def data_write_file(str_file, deposit_path):
str_file = str_file[0:-1]
start_index = int(str_file.find('.')) + 1
end_index = int(str_file.find('='))
filename = str_file[start_index:end_index]
file_content = str_file[end_index + 1:]
with open(os.path.join(deposit_path, '{}.txt'.format(filename)), 'w+', encoding='utf-8') as e:
print(file_content)
left_index = 0
while True:
right_index = file_content.find('}')
if right_index == -1:
break
e.write(file_content[left_index: right_index + 1] + '\n')
file_content = file_content[right_index + 1:]
e.write('}')
if __name__ == "__main__":
path = ''
readfile(path)
对js文件的一些操作,
猜你喜欢
转载自blog.csdn.net/weixin_43633797/article/details/102622164
今日推荐
周排行