Skip to contents

Python's open() and MATLAB's fopen() read a file or write one, decided only by their mode argument. code_file_refs() took the file name in every such call as an input, so open("out.txt", "w") was reported as a missing file when the script itself creates it. This replaces the text of each call that writes with spaces, so its file name is not found; the lines and their number stay as they were. A call over several lines is judged as a whole.

Usage

.code_blank_write_opens(code_text, lang, mode_regex = NULL)

Arguments

code_text

the lines of one file, comments removed

lang

the language; only "Python" and "MATLAB" are changed

mode_regex

the modes that count as a write, matched against the mode argument with its quotes

Value

code_text, with each writing call's text replaced by spaces

Details

The mode is the second argument without a name, or (Python) mode =. The default modes are those that create the file: Python's w, a and x, MATLAB's w and a. r+ changes a file that must already exist, so it is left as an input; .py_open_writes() passes its own modes, which count r+.