def readlevelsfile(filename) assert os path exists(filename)'cannot find the level file% (filenamethe os path exists(function will return true if the file specified by the string passed to the function exists if it does not existos path exists(returns false mapfile open(filename' 'each level must end with blank line content mapfile readlines(['\ \ 'mapfile close(levels [will contain list of level objects levelnum maptextlines [contains the lines for single level' map mapobj [the map object made from the data in maptextlines the file object for the level file that is opened for reading is stored in mapfile all of the text from the level file is stored as list of strings in the content variablewith blank line added to the end (the reason that this is done is explained later after the level objects are createdthey will be stored in the levels list the levelnum variable will keep track of how many levels are found inside the level file the maptextlines list will be list of strings from the content list for single map (as opposed to how content stores the strings of all maps in the level filethe mapobj variable will be list for linenum in range(len(content))process each line that was in the level file line content[linenumrstrip('\ \ 'email questions to the authoral@inventwithpython com