Ensure python 2 support for chapters 13 and 14
parent
c2be4a9be6
commit
206f0e17f4
|
@ -455,7 +455,7 @@
|
||||||
"source": [
|
"source": [
|
||||||
"import sys\n",
|
"import sys\n",
|
||||||
"import tarfile\n",
|
"import tarfile\n",
|
||||||
"import urllib.request\n",
|
"from six.moves import urllib\n",
|
||||||
"\n",
|
"\n",
|
||||||
"TF_MODELS_URL = \"http://download.tensorflow.org/models\"\n",
|
"TF_MODELS_URL = \"http://download.tensorflow.org/models\"\n",
|
||||||
"INCEPTION_V3_URL = TF_MODELS_URL + \"/inception_v3_2016_08_28.tar.gz\"\n",
|
"INCEPTION_V3_URL = TF_MODELS_URL + \"/inception_v3_2016_08_28.tar.gz\"\n",
|
||||||
|
|
|
@ -1476,13 +1476,27 @@
|
||||||
"source": [
|
"source": [
|
||||||
"from six.moves import urllib\n",
|
"from six.moves import urllib\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
"import errno\n",
|
||||||
"import os\n",
|
"import os\n",
|
||||||
"import zipfile\n",
|
"import zipfile\n",
|
||||||
"import urllib.request\n",
|
|
||||||
"\n",
|
"\n",
|
||||||
"WORDS_PATH = \"datasets/words\"\n",
|
"WORDS_PATH = \"datasets/words\"\n",
|
||||||
"WORDS_URL = 'http://mattmahoney.net/dc/text8.zip'\n",
|
"WORDS_URL = 'http://mattmahoney.net/dc/text8.zip'\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
"def mkdir_p(path):\n",
|
||||||
|
" \"\"\"Create directories, ok if they already exist.\n",
|
||||||
|
" \n",
|
||||||
|
" This is for python 2 support. In python >=3.2, simply use:\n",
|
||||||
|
" >>> os.makedirs(path, exist_ok=True)\n",
|
||||||
|
" \"\"\"\n",
|
||||||
|
" try:\n",
|
||||||
|
" os.makedirs(path)\n",
|
||||||
|
" except OSError as exc:\n",
|
||||||
|
" if exc.errno == errno.EEXIST and os.path.isdir(path):\n",
|
||||||
|
" pass\n",
|
||||||
|
" else:\n",
|
||||||
|
" raise\n",
|
||||||
|
"\n",
|
||||||
"def fetch_words_data(words_url=WORDS_URL, words_path=WORDS_PATH):\n",
|
"def fetch_words_data(words_url=WORDS_URL, words_path=WORDS_PATH):\n",
|
||||||
" os.makedirs(words_path, exist_ok=True)\n",
|
" os.makedirs(words_path, exist_ok=True)\n",
|
||||||
" zip_path = os.path.join(words_path, \"words.zip\")\n",
|
" zip_path = os.path.join(words_path, \"words.zip\")\n",
|
||||||
|
|
Loading…
Reference in New Issue