Python Forum

Full Version: How can and I read and write css files
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I want to read and write with css files, but I don't know how I would do this since I get an error when I try to use redlines with a css files. I'd appreciate if someone could point me in the right direction. Thanks in advance.
Edit: The error says "UnsupportedOperation: not readable"
CSS is just a text format,so can read and write in stander way.
If you are not taking about how a web-framework read a CSS file?

style.css
Output:
body { background: #67B26F; } html { height: 100% } #wrapper { width: auto; }
with open('style.css') as f:
    css_file = f.read()

new = css_file.replace('html', 'rubberduck')

with open('new.css', 'w') as f_out:
    f_out.write(new)
new.css
Output:
body { background: #67B26F; } rubberduck { height: 100% } #wrapper { width: auto; }
Oh, I just realized how stupid I am. I had it on writing mode, I just changed it to w+ so I can read and write in it.