Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- __author__ = 'nivs'
- import re
- import os
- import shutil
- import copy
- book = open('text.txt','r')
- file = ""
- nameOfList = {}
- lvl = 0
- root = "/home/nivs/projects/python/my_programs/PyQTBook/"
- buf1 = ""
- buf2 = ""
- start = True
- for line in book.readlines():
- if not re.match(r"\n", line):
- reg = re.match(r"^((?!Листинг)[а-яА-ЯM].*)", line)
- reg2 = re.match(r"Листинг \d+\. (.*)", line)
- if reg:
- lvl += 1
- if lvl == 2:
- buf2 = reg.group(1)
- elif lvl == 1:
- buf1 = reg.group(1)
- if not start:
- file.close()
- elif reg2:
- start = False
- if lvl == 2:
- os.makedirs(root + buf2)
- os.makedirs(root + buf2 + "/" + buf1)
- lvl = 0
- file = open(root + buf2 + "/" + buf1 + "/" + reg2.group(1), "w")
- file.writelines("#!/usr/bin/python3\n")
- elif lvl == 1:
- os.makedirs(root + buf2 + "/" + buf1)
- lvl = 0
- file = open(root + buf2 + "/" + buf1 + "/" + reg2.group(1), "w")
- file.writelines("#!/usr/bin/python3\n")
- else:
- lvl = 0
- file = open(root + buf2 + "/" + buf1 + "/" + reg2.group(1), "w")
- file.writelines("#!/usr/bin/python3\n")
- else:
- file.writelines(line)
- print("_" * 30)
Advertisement
Add Comment
Please, Sign In to add comment