MCPcopy Index your code
hub / github.com/python/cpython / view_file

Function view_file

Lib/idlelib/textview.py:164–185  ·  view source on GitHub ↗

Create text viewer for text in filename. Return error message if file cannot be read. Otherwise calls view_text with contents of the file.

(parent, title, filename, encoding, modal=True, wrap='word',
              _utest=False)

Source from the content-addressed store, hash-verified

162
163
164def view_file(parent, title, filename, encoding, modal=True, wrap='word',
165 _utest=False):
166 """Create text viewer for text in filename.
167
168 Return error message if file cannot be read. Otherwise calls view_text
169 with contents of the file.
170 """
171 try:
172 with open(filename, encoding=encoding) as file:
173 contents = file.read()
174 except OSError:
175 showerror(title='File Load Error',
176 message=f'Unable to load file {filename!r} .',
177 parent=parent)
178 except UnicodeDecodeError as err:
179 showerror(title='Unicode Decode Error',
180 message=str(err),
181 parent=parent)
182 else:
183 return view_text(parent, title, contents, modal, wrap=wrap,
184 _utest=_utest)
185 return None
186
187
188if __name__ == '__main__':

Callers

nothing calls this directly

Calls 5

showerrorFunction · 0.90
strFunction · 0.85
view_textFunction · 0.85
openFunction · 0.50
readMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…