# string.split(separator, maxsplit) # separator is optional and refers to any whitespace as default. It indicates which separator to use when splitting the string # maxsplit is optional and specifies how many splits to do. Default value is -1, whichis "all occurrences" ---- # Below, we try to extract "stephen.marquard" from "From stephen.marquard@uct.ac.za Sat Jan 5 09:14:16 2008". line = "From stephen.marquard@uct.ac.za Sat Jan 5 09:14:16 2008" words = line.split() # words = ['From', 'stephen.marquard@uct.ac.za', 'Sat', 'Jan', '5', '09:14:16', '2008'] email = words[1] # email = stephen.marquard@uct.ac.za pieces = email.split('@') # pieces = ['stephen.marquard', 'uct.ac.za'] print(pieces[1]) --- # setting the maxsplit parameter to 2, will return a list with 3 elements line = "From stephen.marquard@uct.ac.za Sat Jan 5 09:14:16 2008" words = line.split(' ', 2) print(words) # ['From', 'stephen.marquard@uct.ac.za', 'Sat Jan 5 09:14:16 2008']