Page 116 -
P. 116
ask for help
Know your methods and ask for help
It might be useful to see if the split() method includes any functionality
that might help here. You can ask the IDLE shell to tell you more about the
split() method by using the help() BIF.
>>> help(each_line.split) Looks like “split()” takes
Help on built-in function split: an optional argument.
split(beans)
split(...)
S.split([sep[, maxsplit]]) -> list of strings
Return a list of the words in S, using sep as the
delimiter string. If maxsplit is given, at most maxsplit
splits are done. If sep is not specified or is None, any
whitespace string is a separator and empty strings are
removed from the result.
The optional argument to split() controls how many breaks occur within
your line of data. By default, the data is broken into as many parts as is
possible. But you need only two parts: the name of the character and the line
he spoke.
If you set this optional argument to 1, your line of data is only ever broken
into two pieces, effectively negating the effect of any extra colon on any line.
Let’s try this and see what happens. split(beans, 1)
Geek Bits
IDLE gives you searchable access to the entire Python
documentation set via its Help ➝ Python Docs menu option (which
will open the docs in your web browser). If all you need to see is the
documentation associated with a single method or function, use
the help() BIF within IDLE’s shell.
80 Chapter 3