|
266 | 266 | "Test whether `o` can be used in a `for` loop" |
267 | 267 | ], |
268 | 268 | "text/plain": [ |
269 | | - "<nbdev.showdoc.BasicMarkdownRenderer at 0x103ad5760>" |
| 269 | + "<nbdev.showdoc.BasicMarkdownRenderer>" |
270 | 270 | ] |
271 | 271 | }, |
272 | 272 | "execution_count": null, |
|
798 | 798 | { |
799 | 799 | "data": { |
800 | 800 | "text/plain": [ |
801 | | - "['j', 3, 1]" |
| 801 | + "[5, 0, 11]" |
802 | 802 | ] |
803 | 803 | }, |
804 | 804 | "execution_count": null, |
|
807 | 807 | } |
808 | 808 | ], |
809 | 809 | "source": [ |
| 810 | + "random.seed(0)\n", |
810 | 811 | "random.sample(t, 3)" |
811 | 812 | ] |
812 | 813 | }, |
|
1013 | 1014 | "Retrieve `idx` (can be list of indices, or mask, or int) items" |
1014 | 1015 | ], |
1015 | 1016 | "text/plain": [ |
1016 | | - "<nbdev.showdoc.BasicMarkdownRenderer at 0x1268a5a90>" |
| 1017 | + "<nbdev.showdoc.BasicMarkdownRenderer>" |
1017 | 1018 | ] |
1018 | 1019 | }, |
1019 | 1020 | "execution_count": null, |
|
1056 | 1057 | "Set `idx` (can be list of indices, or mask, or int) items to `o` (which is broadcast if not iterable)" |
1057 | 1058 | ], |
1058 | 1059 | "text/plain": [ |
1059 | | - "<nbdev.showdoc.BasicMarkdownRenderer at 0x1268c9790>" |
| 1060 | + "<nbdev.showdoc.BasicMarkdownRenderer>" |
1060 | 1061 | ] |
1061 | 1062 | }, |
1062 | 1063 | "execution_count": null, |
|
1097 | 1098 | "Unique items, in stable order" |
1098 | 1099 | ], |
1099 | 1100 | "text/plain": [ |
1100 | | - "<nbdev.showdoc.BasicMarkdownRenderer at 0x10798ca90>" |
| 1101 | + "<nbdev.showdoc.BasicMarkdownRenderer>" |
1101 | 1102 | ] |
1102 | 1103 | }, |
1103 | 1104 | "execution_count": null, |
|
1135 | 1136 | "Dict from value to index" |
1136 | 1137 | ], |
1137 | 1138 | "text/plain": [ |
1138 | | - "<nbdev.showdoc.BasicMarkdownRenderer at 0x1268c9c40>" |
| 1139 | + "<nbdev.showdoc.BasicMarkdownRenderer>" |
1139 | 1140 | ] |
1140 | 1141 | }, |
1141 | 1142 | "execution_count": null, |
|
1168 | 1169 | "\n", |
1169 | 1170 | "#### L.filter\n", |
1170 | 1171 | "\n", |
1171 | | - "> L.filter (f=<functionnoopat0x103aff820>, negate=False, gen=False,\n", |
| 1172 | + "> L.filter (f=<functionnoopat0x11542e1f0>, negate=False, gen=False,\n", |
1172 | 1173 | "> **kwargs)\n", |
1173 | 1174 | "\n", |
1174 | 1175 | "Create new `L` filtered by predicate `f`, passing `args` and `kwargs` to `f`" |
1175 | 1176 | ], |
1176 | 1177 | "text/plain": [ |
1177 | | - "<nbdev.showdoc.BasicMarkdownRenderer at 0x1268c9fa0>" |
| 1178 | + "<nbdev.showdoc.BasicMarkdownRenderer>" |
1178 | 1179 | ] |
1179 | 1180 | }, |
1180 | 1181 | "execution_count": null, |
|
1233 | 1234 | "Like `filter`, but return indices for matching items" |
1234 | 1235 | ], |
1235 | 1236 | "text/plain": [ |
1236 | | - "<nbdev.showdoc.BasicMarkdownRenderer at 0x1268d0c70>" |
| 1237 | + "<nbdev.showdoc.BasicMarkdownRenderer>" |
1237 | 1238 | ] |
1238 | 1239 | }, |
1239 | 1240 | "execution_count": null, |
|
1271 | 1272 | "Return index of first matching item" |
1272 | 1273 | ], |
1273 | 1274 | "text/plain": [ |
1274 | | - "<nbdev.showdoc.BasicMarkdownRenderer at 0x1268d0310>" |
| 1275 | + "<nbdev.showdoc.BasicMarkdownRenderer>" |
1275 | 1276 | ] |
1276 | 1277 | }, |
1277 | 1278 | "execution_count": null, |
|
1309 | 1310 | "Create new `L` with `f` applied to all `items`, passing `args` and `kwargs` to `f`" |
1310 | 1311 | ], |
1311 | 1312 | "text/plain": [ |
1312 | | - "<nbdev.showdoc.BasicMarkdownRenderer at 0x1268e82e0>" |
| 1313 | + "<nbdev.showdoc.BasicMarkdownRenderer>" |
1313 | 1314 | ] |
1314 | 1315 | }, |
1315 | 1316 | "execution_count": null, |
|
1391 | 1392 | "\n", |
1392 | 1393 | "#### L.map_dict\n", |
1393 | 1394 | "\n", |
1394 | | - "> L.map_dict (f=<functionnoopat0x103aff820>, *args, gen=False, **kwargs)\n", |
| 1395 | + "> L.map_dict (f=<functionnoopat0x11542e1f0>, *args, gen=False, **kwargs)\n", |
1395 | 1396 | "\n", |
1396 | 1397 | "Like `map`, but creates a dict from `items` to function results" |
1397 | 1398 | ], |
1398 | 1399 | "text/plain": [ |
1399 | | - "<nbdev.showdoc.BasicMarkdownRenderer at 0x1268f4af0>" |
| 1400 | + "<nbdev.showdoc.BasicMarkdownRenderer>" |
1400 | 1401 | ] |
1401 | 1402 | }, |
1402 | 1403 | "execution_count": null, |
|
1435 | 1436 | "Create new `L` with `zip(*items)`" |
1436 | 1437 | ], |
1437 | 1438 | "text/plain": [ |
1438 | | - "<nbdev.showdoc.BasicMarkdownRenderer at 0x1268f4520>" |
| 1439 | + "<nbdev.showdoc.BasicMarkdownRenderer>" |
1439 | 1440 | ] |
1440 | 1441 | }, |
1441 | 1442 | "execution_count": null, |
|
1485 | 1486 | "Combine `zip` and `starmap`" |
1486 | 1487 | ], |
1487 | 1488 | "text/plain": [ |
1488 | | - "<nbdev.showdoc.BasicMarkdownRenderer at 0x1268f6c70>" |
| 1489 | + "<nbdev.showdoc.BasicMarkdownRenderer>" |
1489 | 1490 | ] |
1490 | 1491 | }, |
1491 | 1492 | "execution_count": null, |
|
1524 | 1525 | "Create new `L` with `self` zip with each of `*rest`" |
1525 | 1526 | ], |
1526 | 1527 | "text/plain": [ |
1527 | | - "<nbdev.showdoc.BasicMarkdownRenderer at 0x1268f69a0>" |
| 1528 | + "<nbdev.showdoc.BasicMarkdownRenderer>" |
1528 | 1529 | ] |
1529 | 1530 | }, |
1530 | 1531 | "execution_count": null, |
|
1564 | 1565 | "Combine `zipwith` and `starmap`" |
1565 | 1566 | ], |
1566 | 1567 | "text/plain": [ |
1567 | | - "<nbdev.showdoc.BasicMarkdownRenderer at 0x1269028e0>" |
| 1568 | + "<nbdev.showdoc.BasicMarkdownRenderer>" |
1568 | 1569 | ] |
1569 | 1570 | }, |
1570 | 1571 | "execution_count": null, |
|
1602 | 1603 | "Create new `L` with item `idx` of all `items`" |
1603 | 1604 | ], |
1604 | 1605 | "text/plain": [ |
1605 | | - "<nbdev.showdoc.BasicMarkdownRenderer at 0x1269025b0>" |
| 1606 | + "<nbdev.showdoc.BasicMarkdownRenderer>" |
1606 | 1607 | ] |
1607 | 1608 | }, |
1608 | 1609 | "execution_count": null, |
|
1640 | 1641 | "Create new `L` with attr `k` (or value `k` for dicts) of all `items`." |
1641 | 1642 | ], |
1642 | 1643 | "text/plain": [ |
1643 | | - "<nbdev.showdoc.BasicMarkdownRenderer at 0x1079e73d0>" |
| 1644 | + "<nbdev.showdoc.BasicMarkdownRenderer>" |
1644 | 1645 | ] |
1645 | 1646 | }, |
1646 | 1647 | "execution_count": null, |
|
1684 | 1685 | "New `L` sorted by `key`. If key is str use `attrgetter`; if int use `itemgetter`" |
1685 | 1686 | ], |
1686 | 1687 | "text/plain": [ |
1687 | | - "<nbdev.showdoc.BasicMarkdownRenderer at 0x10792bfd0>" |
| 1688 | + "<nbdev.showdoc.BasicMarkdownRenderer>" |
1688 | 1689 | ] |
1689 | 1690 | }, |
1690 | 1691 | "execution_count": null, |
|
1722 | 1723 | "Class Method: Same as `str.split`, but returns an `L`" |
1723 | 1724 | ], |
1724 | 1725 | "text/plain": [ |
1725 | | - "<nbdev.showdoc.BasicMarkdownRenderer at 0x107958f70>" |
| 1726 | + "<nbdev.showdoc.BasicMarkdownRenderer>" |
1726 | 1727 | ] |
1727 | 1728 | }, |
1728 | 1729 | "execution_count": null, |
|
1760 | 1761 | "Class Method: Same as `range`, but returns `L`. Can pass collection for `a`, to use `len(a)`" |
1761 | 1762 | ], |
1762 | 1763 | "text/plain": [ |
1763 | | - "<nbdev.showdoc.BasicMarkdownRenderer at 0x107958220>" |
| 1764 | + "<nbdev.showdoc.BasicMarkdownRenderer>" |
1764 | 1765 | ] |
1765 | 1766 | }, |
1766 | 1767 | "execution_count": null, |
|
1799 | 1800 | "Concatenate all elements of list" |
1800 | 1801 | ], |
1801 | 1802 | "text/plain": [ |
1802 | | - "<nbdev.showdoc.BasicMarkdownRenderer at 0x107958f40>" |
| 1803 | + "<nbdev.showdoc.BasicMarkdownRenderer>" |
1803 | 1804 | ] |
1804 | 1805 | }, |
1805 | 1806 | "execution_count": null, |
|
1837 | 1838 | "Same as `list.copy`, but returns an `L`" |
1838 | 1839 | ], |
1839 | 1840 | "text/plain": [ |
1840 | | - "<nbdev.showdoc.BasicMarkdownRenderer at 0x10795f670>" |
| 1841 | + "<nbdev.showdoc.BasicMarkdownRenderer>" |
1841 | 1842 | ] |
1842 | 1843 | }, |
1843 | 1844 | "execution_count": null, |
|
1871 | 1872 | "\n", |
1872 | 1873 | "#### L.map_first\n", |
1873 | 1874 | "\n", |
1874 | | - "> L.map_first (f=<functionnoopat0x103aff820>,\n", |
1875 | | - "> g=<functionnoopat0x103aff820>, *args, **kwargs)\n", |
| 1875 | + "> L.map_first (f=<functionnoopat0x11542e1f0>,\n", |
| 1876 | + "> g=<functionnoopat0x11542e1f0>, *args, **kwargs)\n", |
1876 | 1877 | "\n", |
1877 | 1878 | "First element of `map_filter`" |
1878 | 1879 | ], |
1879 | 1880 | "text/plain": [ |
1880 | | - "<nbdev.showdoc.BasicMarkdownRenderer at 0x10791fe80>" |
| 1881 | + "<nbdev.showdoc.BasicMarkdownRenderer>" |
1881 | 1882 | ] |
1882 | 1883 | }, |
1883 | 1884 | "execution_count": null, |
|
1916 | 1917 | "Call `setattr` on all items" |
1917 | 1918 | ], |
1918 | 1919 | "text/plain": [ |
1919 | | - "<nbdev.showdoc.BasicMarkdownRenderer at 0x10793e0a0>" |
| 1920 | + "<nbdev.showdoc.BasicMarkdownRenderer>" |
1920 | 1921 | ] |
1921 | 1922 | }, |
1922 | 1923 | "execution_count": null, |
|
2003 | 2004 | "#|export\n", |
2004 | 2005 | "class Config:\n", |
2005 | 2006 | " \"Reading and writing `ConfigParser` ini files\"\n", |
2006 | | - " def __init__(self, cfg_path, cfg_name, create=None):\n", |
| 2007 | + " def __init__(self, cfg_path, cfg_name, create=None, save=True):\n", |
2007 | 2008 | " cfg_path = Path(cfg_path).expanduser().absolute()\n", |
2008 | 2009 | " self.config_path,self.config_file = cfg_path,cfg_path/cfg_name\n", |
2009 | | - " if not self.config_file.exists():\n", |
2010 | | - " if create:\n", |
2011 | | - " self.d = create\n", |
| 2010 | + " if self.config_file.exists(): self.d = read_config_file(self.config_file)\n", |
| 2011 | + " elif create is not None:\n", |
| 2012 | + " self.d = ConfigParser(create)['DEFAULT']\n", |
| 2013 | + " if save:\n", |
2012 | 2014 | " cfg_path.mkdir(exist_ok=True, parents=True)\n", |
2013 | 2015 | " self.save()\n", |
2014 | | - " else: raise FileNotFoundError(f\"Could not find {cfg_name}\")\n", |
2015 | | - " self.d = read_config_file(self.config_file)\n", |
2016 | 2016 | "\n", |
2017 | 2017 | " def __setitem__(self,k,v): self.d[k] = str(v)\n", |
2018 | 2018 | " def __contains__(self,k): return k in self.d\n", |
|
2030 | 2030 | "cell_type": "markdown", |
2031 | 2031 | "metadata": {}, |
2032 | 2032 | "source": [ |
2033 | | - "`Config` and provides direct access to the 'DEFAULT' section of a `ConfigParser` ini file." |
| 2033 | + "`Config` is a convenient wrapper around `ConfigParser` ini files with a single section (`DEFAULT`)." |
2034 | 2034 | ] |
2035 | 2035 | }, |
2036 | 2036 | { |
|
2048 | 2048 | "test_eq(cfg.get('foo','bar'),'bar')" |
2049 | 2049 | ] |
2050 | 2050 | }, |
| 2051 | + { |
| 2052 | + "cell_type": "markdown", |
| 2053 | + "metadata": {}, |
| 2054 | + "source": [ |
| 2055 | + "You can also create an in-memory `Config` by passing `save=False`:" |
| 2056 | + ] |
| 2057 | + }, |
| 2058 | + { |
| 2059 | + "cell_type": "code", |
| 2060 | + "execution_count": null, |
| 2061 | + "metadata": {}, |
| 2062 | + "outputs": [], |
| 2063 | + "source": [ |
| 2064 | + "cfg = Config('..', 'tmp.ini', create=_d, save=False)\n", |
| 2065 | + "test_eq(cfg.user,'fastai')\n", |
| 2066 | + "assert not Path('../tmp.ini').exists()" |
| 2067 | + ] |
| 2068 | + }, |
2051 | 2069 | { |
2052 | 2070 | "cell_type": "markdown", |
2053 | 2071 | "metadata": {}, |
|
2059 | 2077 | "cell_type": "code", |
2060 | 2078 | "execution_count": null, |
2061 | 2079 | "metadata": {}, |
2062 | | - "outputs": [ |
2063 | | - { |
2064 | | - "name": "stdout", |
2065 | | - "output_type": "stream", |
2066 | | - "text": [ |
2067 | | - "Converted 00_test.ipynb.\n", |
2068 | | - "Converted 01_basics.ipynb.\n", |
2069 | | - "Converted 02_foundation.ipynb.\n", |
2070 | | - "Converted 03_xtras.ipynb.\n", |
2071 | | - "Converted 03a_parallel.ipynb.\n", |
2072 | | - "Converted 03b_net.ipynb.\n", |
2073 | | - "Converted 04_dispatch.ipynb.\n", |
2074 | | - "Converted 05_transform.ipynb.\n", |
2075 | | - "Converted 06_docments.ipynb.\n", |
2076 | | - "Converted 07_meta.ipynb.\n", |
2077 | | - "Converted 08_script.ipynb.\n", |
2078 | | - "Converted index.ipynb.\n", |
2079 | | - "Converted parallel_win.ipynb.\n" |
2080 | | - ] |
2081 | | - } |
2082 | | - ], |
| 2080 | + "outputs": [], |
2083 | 2081 | "source": [ |
2084 | 2082 | "#|hide\n", |
2085 | 2083 | "#|eval: false\n", |
|
0 commit comments