Dive Into Python-Chapter 1. Installing Python
... Open the MacPython-2.3 folder Unpacking python (from /python_ 2.3 .1- 1_all.deb) Setting up python (2.3 .1- 1) Setting up python2 .3 (2.3 .1- 1) Compiling python modules in /usr/lib /python2 .3 Compiling ... of Python. Procedure 1. 1. Option 1: Installing ActivePython Here is the procedure for installing ActivePython: 1. Download ActivePython from http://www.activesta...
Ngày tải lên: 07/11/2013, 10:15
... word python . Example 12 .2. Sample Usage of search.py C:\diveintopython\common\py> python search.py " ;python& quot; <b> ;Python& lt;/b> Programming Language http://www .python. org/ ... <b> </b> <b> ;Python& lt;/b> is OSI Certified Open Source: Pythonline http://www.pythonline.com/ Dive Into <b> ;Python& lt;/b> http://diveint...
Ngày tải lên: 17/10/2013, 19:15
Dive Into Python-Chapter 13. Unit Testing
... 'MXLIII'), (11 10, 'MCX'), (12 26, 'MCCXXVI'), (13 01, 'MCCCI'), (14 85, 'MCDLXXXV'), (15 09, 'MDIX'), (16 07, 'MDCVII'), (17 54, 'MDCCLIV'), ... input""" (12 26, 'MCCXXVI'), (13 01, 'MCCCI'), (14 85, 'MCDLXXXV'), (15 09, 'MDIX'), (16 0...
Ngày tải lên: 20/10/2013, 10:15
Dive Into Python-Chapter 14. Test-First Programming
... "C:\docbook\dip\py\roman\stage1\romantest1.py", line 11 2, in testNegative self.assertRaises(roman1.OutOfRangeError, roman1.toRoman, -1) File "c: \python 21\ lib\unittest.py", line ... "C:\docbook\dip\py\roman\stage1\romantest1.py", line 12 2, in testTooManyRepeatedNumerals self.assertRaises(roman1.InvalidRomanNumeralError, roman1.fromRoman, s) File...
Ngày tải lên: 20/10/2013, 10:15
Dive Into Python-Chapter 15. Refactoring
... (13 01, 'MCCCI'), (14 85, 'MCDLXXXV'), (15 09, 'MDIX'), (16 07, 'MDCVII'), (17 54, 'MDCCLIV'), (18 32, 'MDCCCXXXII'), (19 93, ... roman 71. fromRoman(numeral) self.assertEqual(integer, result) class ToRomanBadInput(unittest.TestCase): def testTooLarge(self): (10 43, 'MXLIII'), (11 10, 'MCX&apos...
Ngày tải lên: 24/10/2013, 09:15
Dive Into Python-Chapter 16. Functional Programming
... from there. Example 16 .17 . Step 1: Get all the files return n*2 >>> li = [1, 2, 3, 5, 9, 10 , 256, -3] >>> map(double, li) 1 [2, 4, 6, 10 , 18 , 20, 512 , -6] >>> ... 2 [2, 4, 6, 10 , 18 , 20, 512 , -6] >>> newlist = [] >>> for n in li: 3 newlist.append(double(n)) >>> newlist [2, 4, 6, 10 , 18 , 20, 512 , -6]...
Ngày tải lên: 24/10/2013, 09:15
Dive Into Python-Chapter 17. Dynamic functions
... with for loops. Example 17 .20. Generators in for loops >>> for n in fibonacci (10 00): 1 print n, 2 0 1 1 2 3 5 8 13 21 34 55 89 14 4 233 377 610 987 1 You can use a generator ... generators instead. Example 17 .19 . Using generators instead of recursion def fibonacci(max): a, b = 0, 1 1 while a < max: yield a 2 a, b = b, a+b 3 1 The Fibonacc...
Ngày tải lên: 28/10/2013, 16:15
Dive Into Python-Chapter 18. Performance Tuning
... "import soundex") 1 >>> t.timeit() 2 8. 216 83733547 >>> t.repeat(3, 2000000) 3 [16 .48 319 30 910 9, 16 .4 612 8984923, 16 .44203948 912 ] 1 The timeit module defines one ... C:\samples\soundex\stage1> ;python soundex1b.py Woo W000 17 .13 611 33887 Pilgrim P426 21. 82 016 93232 Flingjingwaller F452 32.7262294509 # Soundex algorithm: #...
Ngày tải lên: 28/10/2013, 16:15
... ['', '/usr/local/lib /python2 .2', '/usr/local/lib /python2 .2/plat-linux2', '/usr/local/lib /python2 .2/lib-dynload', '/usr/local/lib /python2 .2/site-packages', ... function argument. In Python, you never explicitly specify the datatype of anything. Based on what value you assign, Python keeps track of the datatype internally. 2.2 ....
Ngày tải lên: 07/11/2013, 10:15
Dive Into Python-Chapter 3. Native Datatypes
... >>> li = [1, 9, 8, 4] >>> [elem*2 for elem in li] [2, 18 , 16 , 8] >>> li [1, 9, 8, 4] >>> li = [elem*2 for elem in li] >>> li [2, 18 , 16 , 8] If ... The * operator works on lists as a repeater. li = [1, 2] * 3 is equivalent to li = [1, 2] + [1, 2] + [1, 2], which concatenates the three lists into one. Further Reading on List...
Ngày tải lên: 07/11/2013, 10:15