I want to implement a script that reads a CSS file and makes meaningful changes to it (adding/removing/replacing lines/words etc.). The basic logic is implement an RTL (right-to-left) transformation.
I could think of quite a few approaches to it:
basically what I'm wondering is which of those, or other methods, would be the python way to do it? are there any relevant libraries you think I should be familiar with for this kind of operation?
Edit: it's should be noted that this is a "learn python through this usable project" kind of project so I'm not familiar with most libraries you would mention here.
If you want something "quick and dirty" there are many interesting ways to do this. (As you said: line-by-line, regular expressions, …)
But if you want to do it "right" (correct on all kinds of inputs) you’ll need a real parser based on the official CSS tokenization and grammar. In Python there is cssutils and tinycss. (Disclaimer: I’m tinycss’s author.) If you want to learn, I like to think that tinycss’s source code is straightforward and easy to learn :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With