Load a file into a list of strings. Return the (list, newline_string) or (None, None) on failure
(filename)
| 236 | return pi |
| 237 | |
| 238 | def loadFile(filename): |
| 239 | """Load a file into a list of strings. Return the (list, newline_string) or (None, None) on failure""" |
| 240 | newline_string = "\n" |
| 241 | try: |
| 242 | with open(filename, 'rb') as fp: |
| 243 | contents = fp.read() |
| 244 | if contents.count(b"\r\n") > 1: |
| 245 | newline_string = "\r\n" |
| 246 | |
| 247 | with open(filename, 'r', encoding='utf-8') as fp: |
| 248 | lines = fp.readlines() |
| 249 | except: |
| 250 | logWarn(f'Cannot open file {filename} : {sys.exc_info()[0]}') |
| 251 | return None, None |
| 252 | |
| 253 | return lines, newline_string |
| 254 | |
| 255 | def clampToBlock(line, minline, maxline): |
| 256 | """Clamp a line number to be in the range [minline,maxline]. |