0

I have a file where I want to apply the following regex pattern to the file and save it.

Below is my code:

file = open("/home/hive_db_ddls/abc_db_extract_all_tables.sql","a", encoding='latin-1').read()
for line in file:
  re.sub(r'(TBLPROPERTIES \(.*?\))', r'\1;', file, flags=re.DOTALL)

Error I am getting:

Traceback (most recent call last):
  File "/home/python_filter.py", line 4, in <module>
    file = open("/home/hive_db_ddls/abc_db_extract_all_tables.sql","a", encoding='latin-1').read()
io.UnsupportedOperation: not readable

Any suggestion as to why I am receiving this error? I know it should be a small fix but can't seem to find the problem.

StardustGogeta
  • 3,331
  • 2
  • 18
  • 32
James Davinport
  • 303
  • 7
  • 19
  • I think you're going to find your answer [here](https://stackoverflow.com/questions/44901806/python-error-message-io-unsupportedoperation-not-readable) – ldtcoop Jul 24 '19 at 19:27
  • Use `"r"` instead of `"a"`, remove `.read()`, make sure you actually modify the line (`re.sub` returns a copy of the string, strings are immutable in Python) - or write into another file. – Wiktor Stribiżew Jul 24 '19 at 20:01
  • didn't answer my question but thanks – James Davinport Jul 24 '19 at 20:22

0 Answers0