Python 3.2.5 (default, May 15 2013, 23:06:03) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> infile = open("names20.txt", 'r') >>> x = infile.read() >>> x 'Sergio Hester\nYee Taylor\nJorge Sargent\nPeggy Rocha\nMuriel Noble\nLeon Hansen\nDavid Ramirez\nStacy Pickell\nArthur Perry\nTammy Nam\nSusan Wolfe\nSherman Christianson\nBecky Mayor\nJohn Allen\nGilberto Haggerty\nOmar Smith\nStanley Duncan\nAlexander Waugh\nMauricio Smith\nChristina Macon\n' >>> y = infile.read() >>> y '' >>> infile.close() >>> infile = open("names.txt", 'r') Traceback (most recent call last): File "", line 1, in infile = open("names.txt", 'r') IOError: [Errno 2] No such file or directory: 'names.txt' >>> infile = open("names20.txt", 'r') >>> a = infile.readline() >>> a 'Sergio Hester\n' >>> b = infile.readline() >>> b 'Yee Taylor\n' >>> alllines = infile.readlines() >>> alllines ['Jorge Sargent\n', 'Peggy Rocha\n', 'Muriel Noble\n', 'Leon Hansen\n', 'David Ramirez\n', 'Stacy Pickell\n', 'Arthur Perry\n', 'Tammy Nam\n', 'Susan Wolfe\n', 'Sherman Christianson\n', 'Becky Mayor\n', 'John Allen\n', 'Gilberto Haggerty\n', 'Omar Smith\n', 'Stanley Duncan\n', 'Alexander Waugh\n', 'Mauricio Smith\n', 'Christina Macon\n'] >>> type(alllines) >>> allines[7] Traceback (most recent call last): File "", line 1, in allines[7] NameError: name 'allines' is not defined >>> alllines[7] 'Tammy Nam\n' >>> x 'Sergio Hester\nYee Taylor\nJorge Sargent\nPeggy Rocha\nMuriel Noble\nLeon Hansen\nDavid Ramirez\nStacy Pickell\nArthur Perry\nTammy Nam\nSusan Wolfe\nSherman Christianson\nBecky Mayor\nJohn Allen\nGilberto Haggerty\nOmar Smith\nStanley Duncan\nAlexander Waugh\nMauricio Smith\nChristina Macon\n' >>> alllines ['Jorge Sargent\n', 'Peggy Rocha\n', 'Muriel Noble\n', 'Leon Hansen\n', 'David Ramirez\n', 'Stacy Pickell\n', 'Arthur Perry\n', 'Tammy Nam\n', 'Susan Wolfe\n', 'Sherman Christianson\n', 'Becky Mayor\n', 'John Allen\n', 'Gilberto Haggerty\n', 'Omar Smith\n', 'Stanley Duncan\n', 'Alexander Waugh\n', 'Mauricio Smith\n', 'Christina Macon\n'] >>> print(alllines[4]] SyntaxError: invalid syntax >>> print(allines[4]) Traceback (most recent call last): File "", line 1, in print(allines[4]) NameError: name 'allines' is not defined >>> print(alllines[4]) David Ramirez >>> for x in alllines: print(x) Jorge Sargent Peggy Rocha Muriel Noble Leon Hansen David Ramirez Stacy Pickell Arthur Perry Tammy Nam Susan Wolfe Sherman Christianson Becky Mayor John Allen Gilberto Haggerty Omar Smith Stanley Duncan Alexander Waugh Mauricio Smith Christina Macon >>> infile.close() >>> myoutput = open('output.txt', 'w') >>> print("Write this stuff to the file.", file = myoutput) >>> myoutput.close() >>> a 'Sergio Hester\n' >>> c = a.split() >>> c ['Sergio', 'Hester'] >>> c ['Sergio', 'Hester'] >>> c[0] 'Sergio' >>> c[1] 'Hester' >>> f = c[0] >>> last = c[1] >>> f 'Sergio' >>> f[0] 'S' >>> last[0:7] 'Hester' >>> f[0]+last[0:7] 'SHester' >>>