у меня есть следующая текстовая сетка:
File type = "ooTextFile"
Object class = "TextGrid"
xmin = 0
xmax = 3931.56874994773
tiers? <exists>
size = 4
item []:
item [1]:
class = "IntervalTier"
name = "Phrases"
xmin = 0
xmax = 3931.56874994773
intervals: size = 1938
intervals [1]:
xmin = 0
xmax = 3.59246613841739
text = "Good morning"
intervals [2]:
xmin = 3.59246613841739
.
.
item [2]:
class = "IntervalTier"
name = "Phrases_2"
xmin = 0
как разделить этот текст на 4 элемента (элемент [1], элемент [2], элемент [3], элемент [4]) в 4 файлах (имя для каждого файла - это имя в элементе) enter code here например для элемента [1] - это Phrases.textgrid, а для элемента [2] - Phrases_2.textgrid и т. д.






для чтения файла: незнакомец - код:
import os
os.chdir('/python')
# c:\python is my work folder
import re
with open('1.Textgrid','r') as f:
# 1.textgrid is the file to read and split
data = f.read()
#print data #Use this to view how
#the code would look like after the program has opened the files
txttext = ''
#informations needed begin on the 9th lines
for lines in data[9:]:
lines = re.sub('\n','',lines)
#as there's \n at the end of every sentence.
lines = re.sub ('^ *','',lines)
#To remove any special characters
linepair = lines.split('=')
if len(linepair) == 2:
if linepair[0] == 'xmin':
xmin == linepair[1]
if linepair[0] == 'xmax':
xmax == linepair[1]
if linepair[0] == 'text':
if linepair[1].strip().startswith('"')
and linepair[1].strip().endswith('"'):
text = linepair[1].strip()[1:-1]
txttext += text + '\n'
как разбить текст в каждом элементе и записать их в новый файл
Если вы хотите, чтобы мы помогли вам с вашим кодом Python, было бы неплохо включить в вопрос код, с которым вам нужна помощь.