Skip to content

Commit

Permalink
Ensure python 2 support for chapters 13 and 14
Browse files Browse the repository at this point in the history
  • Loading branch information
ageron committed Feb 17, 2017
1 parent c1f10c3 commit 27797c6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion 13_convolutional_neural_networks.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,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",
Expand Down
16 changes: 15 additions & 1 deletion 14_recurrent_neural_networks.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2168,13 +2168,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",
Expand Down

0 comments on commit 27797c6

Please sign in to comment.