Python Forum
How can and I read and write css files
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can and I read and write css files
#1
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"
Reply
#2
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; }
Reply
#3
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  audio read/write library Skaperen 7 3,209 Oct-21-2019, 06:22 AM
Last Post: Larz60+
  Using Python to read and analyze flow cytometry data files dtm04547 3 14,883 Feb-05-2019, 12:35 PM
Last Post: Shwager

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020