Parsing problems: A journey from a text file to a directory tree
Michael J. Fromberger
Michael.J.Fromberger at Clothing.Dartmouth.EDU
Wed Sep 19 17:55:39 EDT 2007
Hi, John,
Your comments below are all reasonable. However, I would like to point
out that the purpose of my example was to provide a demonstration of an
algorithm, not an industrial-grade solution to every aspect of the
original poster's problem. I am confident the original poster can deal
with these aspects of his problem space on his own.
In article <1190154665.944722.137750 at q3g2000prf.googlegroups.com>,
John Machin <sjmachin at lexicon.net> wrote:
> [...]
> > . while new_level < len(state):
> > . state.pop()
>
> Hmmm ... consider rewriting that as the slightly less obfuscatory
>
> while len(state) > new_level:
> state.pop()
This seems to me to be an aesthetic consideration only; I'm not sure I
understand your rationale for reversing the sense of the comparison.
Since it does not change the functionality, it's hardly worthy of
complaint, but I don't see any improvement, either.
> A warning message if there are too many "-" characters might be a good
> idea:
>
> [foo]
> |-bar
> |-zot
> |---plugh
Perhaps so. Again, the original poster will have to decide what should
be the correct response to input of this sort; at present, the
implementation is tolerant of such variations, without loss of
generality.
> And if the input line matches neither regex?
I believe it should be clear that such lines are ignored. Again, this
is an opportunity for the original poster to determine an alternative
response -- perhaps an exception could be raised, if that is his desire.
The problem specification did not constrain this case.
> > To call this, pass a file-like object to parse_folders(), e.g.:
> >
> > test1 = '''
> > [New client].
>
> Won't work with the dot on the end.
My mistake. The period was a copy-and-paste artifact, which I missed.
Cheers,
-M
--
Michael J. Fromberger | Lecturer, Dept. of Computer Science
http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA
More information about the Python-list
mailing list