Python 2.7

2,762 views

Published on

Introduction to Python 2.7

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
2,762
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Python 2.7

  1. 1. Python 2.7<br />ふるかわとおる @torufurukawa<br />株式会社ビープラウド<br />
  2. 2. 2.7 と 3.1.2 が最新安定版<br />
  3. 3. どのバージョンを使うべきか決めないと<br />
  4. 4. バージョンごとの違いが分かればなぁ<br />
  5. 5. 良くも悪くも違いが見えにくい<br />
  6. 6. 大雑把な位置づけ<br />3.0<br />3.1<br />2.5<br />2.6<br />2.7<br />
  7. 7. 3.x と 2.x の断絶<br />3.0<br />3.1<br />2.5<br />2.6<br />2.7<br />
  8. 8. 2.x 系は終了<br />3.0<br />3.1<br />2.5<br />2.6<br />2.7<br />
  9. 9. 3.x からのバックポート<br />3.0<br />3.1<br />2.5<br />2.6<br />2.7<br />
  10. 10. 3.0<br />3.1<br />2.5<br />2.6<br />2.7<br />
  11. 11.
  12. 12. set とdictのリテラル<br />>>> {1,2,3}<br />set([1, 2, 3])<br />>>> {x for x in range(3)}<br />set([0, 1, 2])<br />>>> {i: i*2 for i in range(4)}<br />{0: 0, 1: 2, 2: 4, 3: 6}<br />
  13. 13. OrderedDict<br />>>> from collections import OrderedDict<br />>>> d = OrderedDict([('first',1), ('second',2)])<br />>>> d<br />OrderedDict([('first', 1), ('second', 2)])<br />>>> [x for x in d]<br />['first', 'second’]<br />
  14. 14. unittest.TestCaseの新メソッド<br />assertRegexpMatches(text, regexp, msg=None)<br />assertNotRegexpMatches(text, regexp, msg=None)<br />assertIn(first, second, msg=None)<br />assertNotIn(first, second, msg=None)<br />assertItemsEqual(actual, expected, msg=None)<br />assertSetEqual(set1, set2, msg=None)<br />assertDictEqual(expected, actual, msg=None)<br />assertDictContainsSubset(expected, actual, msg=None)<br />assertListEqual(list1, list2, msg=None)<br />assertTupleEqual(tuple1, tuple2, msg=None)<br />assertSequenceEqual(seq1, seq2, msg=None, seq_type=None)<br />
  15. 15. シーケンスに含まれるかテスト<br /> self.assert_(5 in [1,2,3])<br /> ↓<br />Traceback (most recent call last):<br /> File "bar.py", line 10, in test_in<br /> self.assert_(5 in [1,2,3])<br />AssertionError: False is not True<br />Falesは True ではありません<br />
  16. 16. シーケンスに含まれるかテスト new<br /> self.assertIn(5, [1,2,3])<br /> ↓<br />Traceback (most recent call last):<br /> File "bar.py", line 9, in test_in<br /> self.assertIn(5, [1,2,3])<br />AssertionError: 5 not found in [1, 2, 3]<br />5 は [1,2,3] に、ない<br />
  17. 17. class MyTest(unittest.TestCase):<br />@unittest.expectedFailure # Fail するものとして扱う<br /> def test2(self):<br /> self.assertEqual(1, 2)<br /> @unittest.skip(‘skip me’) # テストしない<br /> def test1(self):<br />self.assertEqual(False, True)<br />
  18. 18. 3.x に興味あるけど、まだ移行できない人におすすめ<br />3.0<br />3.1<br />2.5<br />2.6<br />2.7<br />

×