text read(text 'hello\nworld\ ' (readis the default processing mode read entire file into string print(texthello world print interprets control characters text split(['hello''world'file content is always string other file object methods support additional features we don' have time to cover here for instancefile objects provide more ways of reading and writing (read accepts an optional maximum byte/character sizereadline reads one line at timeand so on)as well as other tools (seek moves to new file positionas we'll see laterthoughthe best way to read file today is to not read it at all--files provide an iterator that automatically reads line by line in for loops and other contextsfor line in open('data txt')print(linewe'll meet the full set of file methods later in this bookbut if you want quick preview nowrun dir call on any open file and help on any of the method names that come backdir(fmany names omitted 'buffer''close''closed''detach''encoding''errors''fileno''flush''isatty''line_buffering''mode''name''newlines''read''readable''readline''readlines''seek''seekable''tell''truncate''writable''write''writelines'help( seektry it and see binary bytes files the prior section' examples illustrate file basics that suffice for many roles technicallythoughthey rely on either the platform' unicode encoding default in python xor the -bit byte nature of files in python text files always encode strings in xand blindly write string content in this is irrelevant for the simple ascii data used previouslywhich maps to and from file bytes unchanged but for richer types of datafile interfaces can vary depending on both content and the python line you use as hinted when we met strings earlierpython draws sharp distinction between text and binary data in filestext files represent content as normal str strings and perform unicode encoding and decoding automatically when writing and reading datawhile binary files represent content as special bytes string and allow you to access file content unaltered python supports the same dichotomybut doesn' impose it as rigidlyand its tools differ files