Not really too sure how to word this question, therefore if you don’t particularly understand it then I can try again.
I have a file called example.txt and I’d like to import this into my Python program. Here I will do some calculations with what it contains and other things that are irrelevant.
Instead of me importing this file, going through it line-by-line and extracting the information I want.. can Python do it instead? As in, if I structure the .txt correctly (whether it be key / value pairs seperated by an equals on each line), is there a current Python ‘way’ where it can handle it all and I work with that?
looks like a starting point if I understand you correctly. You need Python 2.6 or 3.x for this.
Another place to look is the
csvmodule that can parse comma-separated value files – and you can tell it to use=as a separator instead. This will abstract away some of the “manual work” in that previous example – but it seems your example doesn’t especially need that kind of abstraction.Another idea:
Now that’s concise and pythonic 🙂