Ensure python 2 support for chapters 13 and 14

main
Aurélien Geron 2017-02-17 22:32:08 +01:00
parent c2be4a9be6
commit 206f0e17f4
2 changed files with 16 additions and 2 deletions

View File

@ -455,7 +455,7 @@
"source": [
"import sys\n",
"import tarfile\n",
"import urllib.request\n",
"from six.moves import urllib\n",
"\n",
"TF_MODELS_URL = \"http://download.tensorflow.org/models\"\n",
"INCEPTION_V3_URL = TF_MODELS_URL + \"/inception_v3_2016_08_28.tar.gz\"\n",

View File

@ -1476,13 +1476,27 @@
"source": [
"from six.moves import urllib\n",
"\n",
"import errno\n",
"import os\n",
"import zipfile\n",
"import urllib.request\n",
"\n",
"WORDS_PATH = \"datasets/words\"\n",
"WORDS_URL = 'http://mattmahoney.net/dc/text8.zip'\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",
" os.makedirs(words_path, exist_ok=True)\n",
" zip_path = os.path.join(words_path, \"words.zip\")\n",