Input now downloads file from github
This commit is contained in:
@@ -38,6 +38,9 @@
|
||||
"%matplotlib inline\n",
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"\n",
|
||||
"import os\n",
|
||||
"import urllib.request\n",
|
||||
"\n",
|
||||
"import re\n",
|
||||
"import numpy as np\n",
|
||||
"import math\n",
|
||||
@@ -65,7 +68,16 @@
|
||||
"\n",
|
||||
"def Input(day, year=2017):\n",
|
||||
" \"Open this day's input file.\"\n",
|
||||
" return open('data/advent{}/input{}.txt'.format(year, day))\n",
|
||||
" directory = 'advent{}/'.format(year)\n",
|
||||
" filename = directory+'input{}.txt'.format(day)\n",
|
||||
" try:\n",
|
||||
" return open(filename)\n",
|
||||
" except FileNotFoundError:\n",
|
||||
" if not os.path.exists(directory):\n",
|
||||
" os.makedirs(directory)\n",
|
||||
"\n",
|
||||
" urllib.request.urlretrieve(\"https://raw.githubusercontent.com/norvig/pytudes/master/data/\" + filename, filename)\n",
|
||||
" return Input(day)\n",
|
||||
" \n",
|
||||
"def array(lines):\n",
|
||||
" \"Parse an iterable of str lines into a 2-D array. If `lines` is a str, splitlines.\"\n",
|
||||
|
||||
Reference in New Issue
Block a user