Page 117 -
P. 117
files and exceptions
Here’s the code in the IDLE edit window. Note the extra argument to the split() method.
The extra argument
controls how “split()”
splits.
With the edit applied and saved, press F5 (or select Run Module from IDLE’s Run menu) to try out this version of
your code:
>>> ================================ RESTART ================================
>>>
Man said: Is this the right room for an argument?
Other Man said: I've told you once.
Man said: No you haven't!
The displayed output is
Other Man said: Yes I have.
Man said: When? abridged to allow the
Other Man said: Just now. important stuff to fit on
... this page.
Other Man said: Anyway, I did.
Man said: You most certainly did not!
Other Man said: Now let's get one thing quite clear: I most definitely told you!
Man said: Oh no you didn't!
Cool. You made it past the
Other Man said: Oh yes I did! line with two colons…
Man said: Oh no you didn't!
Other Man said: Oh yes I did! …but your joy is short lived. There’s
Man said: Oh look, this isn't an argument! ANOTHER ValueError!!
Traceback (most recent call last):
File "/Users/barryp/HeadFirstPython/chapter4/sketch.py", line 5, in <module>
(role, line_spoken) = each_line.split(':', 1)
ValueError: need more than 1 value to unpack
That’s enough to ruin your day. What could be wrong now?
you are here 4 81