##// END OF EJS Templates
simpler python2 compatibility for davinci code
stonebig <stonebig> -
Show More
@@ -17,6 +17,11 from IPython.parallel import Client, Reference
17 17
18 18 from __future__ import division
19 19
20 try : #python2
21 from urllib import urlretrieve
22 except : #python3
23 from urllib.request import urlretrieve
24
20 25 davinci_url = "http://www.gutenberg.org/cache/epub/5000/pg5000.txt"
21 26
22 27 def pwordfreq(view, fnames):
@@ -47,11 +52,7 if __name__ == '__main__':
47 52 if not os.path.exists('davinci.txt'):
48 53 # download from project gutenberg
49 54 print("Downloading Da Vinci's notebooks from Project Gutenberg")
50 try : #python2
51 urllib.urlretrieve(davinci_url, 'davinci.txt')
52 except : #python3
53 import urllib.request
54 urllib.request.urlretrieve(davinci_url, 'davinci.txt')
55 urlretrieve(davinci_url, 'davinci.txt')
55 56
56 57 # Run the serial version
57 58 print("Serial word frequency count:")
@@ -60,7 +61,7 if __name__ == '__main__':
60 61 freqs = wordfreq(text)
61 62 toc = time.time()
62 63 print_wordfreq(freqs, 10)
63 print("Took %.3f s to calcluate"%(toc-tic))
64 print("Took %.3f s to calculate"%(toc-tic))
64 65
65 66
66 67 # The parallel version
@@ -84,6 +85,6 if __name__ == '__main__':
84 85 pfreqs = pwordfreq(view,fnames)
85 86 toc = time.time()
86 87 print_wordfreq(freqs)
87 print("Took %.3f s to calcluate on %i engines"%(toc-tic, len(view.targets)))
88 print("Took %.3f s to calculate on %i engines"%(toc-tic, len(view.targets)))
88 89 # cleanup split files
89 90 map(os.remove, fnames)
General Comments 0
You need to be logged in to leave comments. Login now