MCPcopy Create free account
hub / github.com/ipython/ipython / read_py_file

Function read_py_file

IPython/utils/openpy.py:60–79  ·  view source on GitHub ↗

Read a Python file, using the encoding declared inside the file. Parameters ---------- filename : str The path to the file to read. skip_encoding_cookie : bool If True (the default), and the encoding declaration is found in the first two lines, that line will b

(filename, skip_encoding_cookie=True)

Source from the content-addressed store, hash-verified

58 yield line
59
60def read_py_file(filename, skip_encoding_cookie=True):
61 """Read a Python file, using the encoding declared inside the file.
62
63 Parameters
64 ----------
65 filename : str
66 The path to the file to read.
67 skip_encoding_cookie : bool
68 If True (the default), and the encoding declaration is found in the first
69 two lines, that line will be excluded from the output.
70
71 Returns
72 -------
73 A unicode string containing the contents of the file.
74 """
75 with open(filename) as f: # the open function defined in this module.
76 if skip_encoding_cookie:
77 return "".join(strip_encoding_cookie(f))
78 else:
79 return f.read()
80
81def read_py_url(url, errors='replace', skip_encoding_cookie=True):
82 """Read a Python file from a URL, using the encoding declared inside the file.

Callers 1

pfileMethod · 0.90

Calls 2

strip_encoding_cookieFunction · 0.85
readMethod · 0.80

Tested by

no test coverage detected