#pyNWC-a .nwctxt syntax parser in python #Created by forum user kahman. #Use it however you please. Feel free to modify it, but please return all modifications to the forum. #Known bugs: # *Cannot import lyrics that have line-breaks in them. def parsefile(_file): "parse one file""" _file=_file.split('\n') #split the file by line for x in range(len(_file)): #for each remaining line, _file[x]=parseline(_file[x]) #parse it seperately while 1: #until error occurs try: _file.remove(None) #remove a None from the list except ValueError: #if there is no None, break #break return _file def parseline(line): output=[] if line=='': #if line is blank, return None #destroy it elif line[0]=='#': #or if it's a comment, return None #destroy it elif line[0]=='!': #or if it's start/end marker, return None #destroy it line=line.split('|') #split the line by | output.append(line[1]) #set what object it is output.append({}) for x in line[2:]: #then for each property/value y=(x.split(':')) #split it into property and value output[1][y[0]]=y[1] #and add these to the dictionary return output