|
725 | 725 | <span class="hljs-number">30</span> |
726 | 726 | </code></pre> |
727 | 727 | <ul> |
728 | | -<li><strong>Partial is also useful in cases when function needs to be passed as an argument because it enables us to set its arguments beforehand.</strong></li> |
| 728 | +<li><strong>Partial is also useful in cases when a function needs to be passed as an argument because it enables us to set its arguments beforehand.</strong></li> |
729 | 729 | <li><strong>A few examples being: <code class="python hljs"><span class="hljs-string">'defaultdict(<func>)'</span></code>, <code class="python hljs"><span class="hljs-string">'iter(<func>, to_exc)'</span></code> and dataclass's <code class="python hljs"><span class="hljs-string">'field(default_factory=<func>)'</span></code>.</strong></li> |
730 | 730 | </ul> |
731 | 731 | <div><h3 id="nonlocal">Non-Local</h3><p><strong>If variable is being assigned to anywhere in the scope, it is regarded as a local variable, unless it is declared as a 'global' or a 'nonlocal'.</strong></p><pre><code class="python language-python hljs"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">get_counter</span><span class="hljs-params">()</span>:</span> |
|
1399 | 1399 | <pre><code class="python language-python hljs"><stat> = os.stat(<path>) <span class="hljs-comment"># Or: <DirEntry/Path>.stat()</span> |
1400 | 1400 | <num> = <stat>.st_mtime/st_size/… <span class="hljs-comment"># Modification time, size in bytes, ...</span> |
1401 | 1401 | </code></pre> |
1402 | | -<div><h3 id="direntry">DirEntry</h3><p><strong>Unlike listdir(), scandir() returns DirEntry objects that cache isfile, isdir and on Windows also stat information, thus significantly increasing the performance of code that requires it.</strong></p><pre><code class="python language-python hljs"><iter> = os.scandir(path=<span class="hljs-string">'.'</span>) <span class="hljs-comment"># Returns DirEntry objects located at the path.</span> |
| 1402 | +<div><h3 id="direntry">DirEntry</h3><p><strong>Unlike listdir(), scandir() returns DirEntry objects that cache isfile, isdir, and on Windows also stat information, thus significantly increasing the performance of code that requires it.</strong></p><pre><code class="python language-python hljs"><iter> = os.scandir(path=<span class="hljs-string">'.'</span>) <span class="hljs-comment"># Returns DirEntry objects located at the path.</span> |
1403 | 1403 | <str> = <DirEntry>.path <span class="hljs-comment"># Returns the whole path as a string.</span> |
1404 | 1404 | <str> = <DirEntry>.name <span class="hljs-comment"># Returns final component as a string.</span> |
1405 | 1405 | <file> = open(<DirEntry>) <span class="hljs-comment"># Opens the file and returns a file object.</span> |
@@ -1863,7 +1863,7 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment |
1863 | 1863 | <li><strong>RotatingFileHandler creates and deletes files based on 'maxBytes', 'backupCount' args.</strong></li> |
1864 | 1864 | <li><strong>An object with <code class="python hljs"><span class="hljs-string">'filter(<LogRecord>)'</span></code> method (or the method itself) can be added to loggers and handlers via addFilter(). Message is dropped if filter() returns a false value.</strong></li> |
1865 | 1865 | </ul> |
1866 | | -<div><h4 id="createsaloggerthatwritesallmessagestofileandsendsthemtotherootshandlerthatprintswarningsorhigher">Creates a logger that writes all messages to file and sends them to the root's handler that prints warnings or higher:</h4><pre><code class="python language-python hljs"><span class="hljs-meta">>>> </span>logger = log.getLogger(<span class="hljs-string">'my_module'</span>) |
| 1866 | +<div><h4 id="createsaloggerthatwritesallmessagestoafileandsendsthemtotherootshandlerthatprintswarningsorhigher">Creates a logger that writes all messages to a file and sends them to the root's handler that prints warnings or higher:</h4><pre><code class="python language-python hljs"><span class="hljs-meta">>>> </span>logger = log.getLogger(<span class="hljs-string">'my_module'</span>) |
1867 | 1867 | <span class="hljs-meta">>>> </span>handler = log.FileHandler(<span class="hljs-string">'test.log'</span>, encoding=<span class="hljs-string">'utf-8'</span>) |
1868 | 1868 | <span class="hljs-meta">>>> </span>handler.setFormatter(log.Formatter(<span class="hljs-string">'%(asctime)s %(levelname)s:%(name)s:%(message)s'</span>)) |
1869 | 1869 | <span class="hljs-meta">>>> </span>logger.addHandler(handler) |
@@ -2062,7 +2062,7 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment |
2062 | 2062 | <div><h3 id="selenium">Selenium</h3><p><strong>Library for scraping websites with dynamic content.</strong></p><pre><code class="python language-python hljs"><span class="hljs-comment"># $ pip3 install selenium</span> |
2063 | 2063 | <span class="hljs-keyword">from</span> selenium <span class="hljs-keyword">import</span> webdriver |
2064 | 2064 |
|
2065 | | -<Drv> = webdriver.Chrome/Firefox/Safari/Edge() <span class="hljs-comment"># Opens the browser. Also <Drv>.quit().</span> |
| 2065 | +<Drv> = webdriver.Chrome/Firefox/Safari/Edge() <span class="hljs-comment"># Opens a browser. Also <Drv>.quit().</span> |
2066 | 2066 | <Drv>.get(<span class="hljs-string">'<url>'</span>) <span class="hljs-comment"># Also <Drv>.implicitly_wait(seconds).</span> |
2067 | 2067 | <El> = <Drv/El>.find_element(<span class="hljs-string">'css selector'</span>, <span class="hljs-string">'<css>'</span>) <span class="hljs-comment"># '<tag>#<id>.<class>[<attr>="<val>"]'.</span> |
2068 | 2068 | <list> = <Drv/El>.find_elements(<span class="hljs-string">'xpath'</span>, <span class="hljs-string">'<xpath>'</span>) <span class="hljs-comment"># '//<tag>[@<attr>="<val>"]'.</span> |
|
0 commit comments