the use of with to open files is quite popularand you are likely to see it in python programs you encounter the keyword with has other uses in python that we will not cover in this bookbut it is particularly common and convenient for reading files and therefore worth mentioning here to actually read file after it has been openedthere are couple of alternatives to the approach above for instancewe can read all the lines into list of strings (linesand then process the list items one by onelines infile readlines(infile close(for line in linesprocess line this approach is very similar to the one used abovebut here we are done working directly with the file after the first lineand the for loop instead traverses the list of strings in practice there is not much difference usuallyprocessing files line by line is very convenientand our good friend the for loop makes such processing quite easy howeverfor files with no natural line structureit can sometimes be easier to read the entire text file into single stringtext infile read(process the string text the data txt file above contain single number for each linewhich is usually not the case more ofteneach line contains many data itemstypically both text and numbersand we might want to treat each one differently for this purpose python' string type has built-in method named split that is extremely useful say we define string variable with some words separated by blank spaces thencalling split(will simply return list containing the individual words in the string by defaultthe words are assumed to be separated by blanksbut if we want different separatorwe can pass it as an argument to split the following code gives some exampless "this is typical stringcsvline "excel;sheets;often;use;semicolon;as;separatorprint( split()print(csvline split()print(csvline split(';')['this''is'' ''typical''string'['excel;sheets;often;use;semicolon;as;separator'['excel''sheets''often''use''semicolon''as''separator'we see that the first attempt to split the string csvline does not work very wellsince the string contains no spaces and the result is therefore list of length one specifying the correct separatoras in the last linesolves the problem to illustrate the use of split in the context of file dataassume we have file with data on rainfall