...hence "RFC" in the title - just wondering if anyone has ideas for how to make things easier for dynamically typed languages. Been thinking more about this and still don't see it.
don't really see the major advantages ... over a comma delimmeted system.
XML as is (without the typing XSD gives it) is a small step from CSV - at least you wont break if your data has a comma it it and it's easier to have flexibile data heirarchies while with CSV you have to stick to rigid columns.
Jofa;
Who said comma delimited? The text files I was talking about in my previous post looked like this:
That sort of format (fixed column widths) is one which Python handles beautifully. Recently had to do something similar, formatting the output of Windows command line tools. Python has is able to treat strings as tuples (indexed arrays) and grab pieces like
Code:
chunk = string[11:15]
So my code goes something like;
Code:
class ColumnDataParser:
def __init__: pass
def parse(self,data):
'''Split data by newlines
data = data.split("\n")
if len(data) == 0:
raise ValueError, "Empty data"
'''Pop off the column headings
data.pop(0)
lines = []
for line in data:
lines.append(self._parseLine(line))
return lines
def _parseLine(self,line):
'''Parse line by column positions
parsedLine = {
'Col1':line[0:21].strip(),
'Col2':line[22:40].strip()
}
return parsedLine
Now way off topic
Bookmarks