Which modules should I use to parse data from a file in Python?

4

I have a list of git repositories addresses sorted according to the location of your hosting.

@GitHub ('@' demonstra que a linha representa um local de hospedagem)
url do repositório a (repositório a ser baixado)
url do repositório b (repositório a ser baixado)
@GoogleCode ('@' demonstra que a linha representa um local de hospedagem)
url do reposiorio c (repositório a ser baixado)
url do repositório d (repositório a ser baixado)

I want to separate this data (what is repository and what is hosting location), which will be in a file written by the user, in the best possible way. My idea is to use some module like ConfigParser, which creates for me a pattern and prevents flaws, unnecessary spaces, etc.

For now I'm doing this on the hand with conditionals (if the first element is '@', set it as the hosting location), I'd like to optimize my code. Any suggestions?

    
asked by anonymous 26.10.2015 / 16:58

1 answer

2

If the format is as simple as that, without any novelty planned, using some parser library, such as ANTLR , can give more work they do what you've already done.

If you have any control over the format, I would first suggest trying to avoid creating a new format and trying to use something with an existing parser, such as JSON, XML or YAML (the most readable of those three).

    
26.10.2015 / 19:08