50 lines
598 B
ReStructuredText
50 lines
598 B
ReStructuredText
Snippets
|
|
========
|
|
|
|
Hello world
|
|
-----------
|
|
|
|
.. code-block:: python3
|
|
|
|
if __name__ == "__main__":
|
|
print("Hello, world!")
|
|
|
|
Files
|
|
-----
|
|
|
|
Links
|
|
^^^^^
|
|
|
|
.. code-block:: python3
|
|
|
|
os.symlink('target', 'tmp_path')
|
|
os.replace('tmp_path', 'path')
|
|
|
|
Remove
|
|
^^^^^^
|
|
|
|
.. code-block:: python3
|
|
|
|
import shutil
|
|
shutil.rmtree(path)
|
|
|
|
Log
|
|
---
|
|
|
|
.. code-block:: python3
|
|
|
|
file_handler = logging.FileHandler('log.txt')
|
|
file_handler.setFormatter(formatter)
|
|
file_handler.setLevel(logging.INFO)
|
|
|
|
logger.addHandler(file_handler)
|
|
|
|
Web
|
|
---
|
|
|
|
Get
|
|
^^^
|
|
|
|
.. code-block:: python3
|
|
|
|
requests.get(url).content.decode(charset)
|