計算機科学のブログ

ほしい物リスト

Python - List of Files: Functions, Modules and Files - unpack, ValueError

Head First Python: A Learner’s Guide to the Fundamentals of Python Programming, A Brain-Friendly GuidePaul Barry(著)、 O’Reilly Mediaの Chapter 4.(List of Files: Functions, Modules & Files)、EXERCISE(229/682)の解答を求めてみる。

Jupyter(コード、入出力結果)

Files.ipynb

for fn in swim_files:
    print(fn)
    swimclub.read_swim_data(fn)
Hannah-13-100m-Free.txt
Darius-13-100m-Back.txt
Owen-15-100m-Free.txt
Mike-15-100m-Free.txt
Hannah-13-100m-Back.txt
Mike-15-100m-Back.txt
Mike-15-100m-Fly.txt
Abi-10-50m-Back.txt



---------------------------------------------------------------------------

ValueError                                Traceback (most recent call last)

Cell In[24], line 3
      1 for fn in swim_files:
      2     print(fn)
----> 3     swimclub.read_swim_data(fn)


File ~/.../swimclub.py:14, in read_swim_data(filename)
     12 converts = []
     13 for t in times:
---> 14     minutes, rest = t.split(':')
     15     seconds, hundredths = rest.split('.')
     16     converts.append(
     17         int(minutes) * 60 * 100 + int(seconds) * 100 + int(hundredths)
     18     )


ValueError: not enough values to unpack (expected 2, got 1)