18
Python 2.7 ふふふふふふふ @torufurukawa ふふふふふふふふふふ

Python 2.7

Embed Size (px)

DESCRIPTION

Introduction to Python 2.7

Citation preview

Page 1: Python 2.7

Python 2.7

ふるかわとおる @torufurukawa株式会社ビープラウド

Page 2: Python 2.7

2.7 と 3.1.2 が最新安定版

Page 3: Python 2.7

どのバージョンを使うべきか決めないと

Page 4: Python 2.7

バージョンごとの違いが分かればなぁ

Page 5: Python 2.7

良くも悪くも違いが見えにくい

Page 6: Python 2.7

大雑把な位置づけ

2.5 2.6 2.7

3.0 3.1

Page 7: Python 2.7

3.x と 2.x の断絶

2.5 2.6 2.7

3.0 3.1

Page 8: Python 2.7

2.x 系は終了

2.5 2.6 2.7

3.0 3.1

Page 9: Python 2.7

3.x からのバックポート

2.5 2.6 2.7

3.0 3.1

Page 10: Python 2.7

2.5 2.6 2.7

3.0 3.1

Page 11: Python 2.7
Page 12: Python 2.7

set と dict のリテラル>>> {1,2,3}set([1, 2, 3])>>> {x for x in range(3)}set([0, 1, 2]) >>> {i: i*2 for i in range(4)}{0: 0, 1: 2, 2: 4, 3: 6}

Page 13: Python 2.7

OrderedDict

>>> from collections import OrderedDict>>> d = OrderedDict([('first',1), ('second',2)])

>>> dOrderedDict([('first', 1), ('second', 2)])>>> [x for x in d]['first', 'second’]

Page 14: Python 2.7

unittest.TestCase の新メソッド• assertRegexpMatches(text, regexp, msg=None)• assertNotRegexpMatches(text, regexp, msg=None)• assertIn(first, second, msg=None)• assertNotIn(first, second, msg=None)• assertItemsEqual(actual, expected, msg=None)• assertSetEqual(set1, set2, msg=None)• assertDictEqual(expected, actual, msg=None)• assertDictContainsSubset(expected, actual, msg=None)• assertListEqual(list1, list2, msg=None)• assertTupleEqual(tuple1, tuple2, msg=None)• assertSequenceEqual(seq1, seq2, msg=None, seq_type=None)

Page 15: Python 2.7

シーケンスに含まれるかテスト self.assert_(5 in [1,2,3])

↓Traceback (most recent call last): File "bar.py", line 10, in test_in self.assert_(5 in [1,2,3])AssertionError: False is not True

Fales は True ではありません

Page 16: Python 2.7

シーケンスに含まれるかテスト new

self.assertIn(5, [1,2,3])↓

Traceback (most recent call last): File "bar.py", line 9, in test_in self.assertIn(5, [1,2,3])AssertionError: 5 not found in [1, 2, 3]

5 は [1,2,3] に、ない

Page 17: Python 2.7

class MyTest(unittest.TestCase): @unittest.expectedFailure # Fail するものとして扱

う def test2(self): self.assertEqual(1, 2)

@unittest.skip(‘skip me’) # テストしない def test1(self): self.assertEqual(False, True)

Page 18: Python 2.7

3.x に興味あるけど、まだ移行できない人におすすめ

2.5 2.6 2.7

3.0 3.1