fork(1) download
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. # Python と Javascript ではじめるデータビジュアライゼーション
  5. # 50ページから
  6.  
  7. nobel_winners = [
  8. {'category': 'Physics',
  9. 'name': 'Albert Einstein',
  10. 'nationality': 'Swiss',
  11. 'sex': 'male',
  12. 'year': '1921'},
  13. {'category': 'Physics',
  14. 'name': 'Paul Dirac',
  15. 'nationality': 'British',
  16. 'sex': 'male',
  17. 'year': '1933'},
  18. {'category': 'Chemistry',
  19. 'name': 'Marie Curie',
  20. 'nationality': 'Polish',
  21. 'sex': 'Female',
  22. 'year': '1911'}
  23. ]
  24.  
  25. f = open('data/nobel_winners.csv', 'w')
  26.  
  27. cols = nobel_winners[0].keys()
  28. cols.sort()
  29.  
  30. with open('data/nobel_winners.csv', 'w') as f:
  31. f.write(','.join(cols) + '\n')
  32.  
  33. for o in nobel_winners:
  34. row = [str(o[col]) for col in cols]
  35. f.write(','.join(row) + '\n')
  36.  
Runtime error #stdin #stdout #stderr 0.03s 27712KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 25, in <module>
FileNotFoundError: [Errno 2] No such file or directory: 'data/nobel_winners.csv'