From f8f9234401e9306d23873dc285a886a0c73a4133 2014-01-14 18:28:12 From: stonebig Date: 2014-01-14 18:28:12 Subject: [PATCH] simpler way to have python2 compatibility --- diff --git a/examples/parallel/pi/pidigits.py b/examples/parallel/pi/pidigits.py index c1235ae..d0937ee 100644 --- a/examples/parallel/pi/pidigits.py +++ b/examples/parallel/pi/pidigits.py @@ -21,7 +21,12 @@ from __future__ import division, with_statement import numpy as np from matplotlib import pyplot as plt -# Top-level functions +try : #python2 + from urllib import urlretrieve +except : #python3 + from urllib.request import urlretrieve + + # Top-level functions def fetch_pi_file(filename): """This will download a segment of pi from super-computing.org @@ -34,11 +39,7 @@ def fetch_pi_file(filename): return else: # download it - try : #python2 - urllib.urlretrieve(ftpdir+filename,filename) - except : #python3 - import urllib.request - urllib.request.urlretrieve(ftpdir+filename,filename) + urlretrieve(ftpdir+filename,filename) def compute_one_digit_freqs(filename): """