like indexingadditionand so onf open('datafile txt'line readline(line 'spam\nline rstrip('spamopen again read one line remove end-of-line for this first linewe used the string rstrip method to get rid of the trailing end-of-line charactera line[:- slice would worktoobut only if we can be sure all lines end in the \ character (the last line in file sometimes does notso farwe've read the line containing the string now let' grab the next linewhich contains numbersand parse out (that isextractthe objects on that lineline readline(line ' , , \nparts line split(','parts [' '' '' \ 'next line from file it' string here split (parseon commas we used the string split method here to chop up the line on its comma delimitersthe result is list of substrings containing the individual numbers we still must convert from strings to integersthoughif we wish to perform math on theseint(parts[ ] numbers [int(pfor in partsnumbers [ convert from string to int convert all in list at once as we have learnedint translates string of digits into an integer objectand the list comprehension expression introduced in can apply the call to each item in our list all at once (you'll find more on list comprehensions later in this booknotice that we didn' have to run rstrip to delete the \ at the end of the last partint and some other converters quietly ignore whitespace around digits finallyto convert the stored list and dictionary in the third line of the filewe can run them through evala built-in function that treats string as piece of executable program code (technicallya string containing python expression)line readline(line "[ ]${' ' ' ' }\nparts line split('$'parts ['[ ]'"{' ' ' ' }\ "eval(parts[ ][ objects [eval(pfor in partssplit (parseon convert to any object type do same for all in list files