Page 118 -
P. 118

missing colon


           Know your data (better)


          Your code has raised another ValueError, but this time, instead of
           complaining that there are “too many values,” the Python interpreter is
           complaining that it doesn’t have enough data to work with: “need more than
          1 value to unpack.” Hopefully, another quick look at the data will clear up the
           mystery of the missing data.



                 Other Man: Now let's get one thing quite clear: I most definitely told you!
                  Man: Oh no you didn't!
                 Other Man: Oh yes I did!
                  Man: Oh no you didn't!
                 Other Man: Oh yes I did!
                  Man: Oh look, this isn't an argument!
                 (pause)
                 Other Man: Yes it is!           What’s this?!? Some of the data doesn’t conform to
                 Man: No it isn’t!               the expected format…which can’t be good.
                 (pause)
                 Man: It's just contradiction!
                 Other Man: No it isn't!


          The case of the missing colon

           Some of the lines of data contain no colon, which causes a problem when
           the split() method goes looking for it. The lack of a colon prevents
           split() from doing its job, causes the runtime error, which then results in
           the complaint that the interpreter needs “more than 1 value.”


                                           It looks like you still have
                                           problems with the data in
                                           your file. What a shame it’s
                                           not in a standard format.













           82    Chapter 3
   113   114   115   116   117   118   119   120   121   122   123