help/rtfd/public/python3/snippets.rst

51 lines
598 B
ReStructuredText
Raw Normal View History

2017-12-02 23:02:37 +01:00
Snippets
2019-08-06 09:30:14 +02:00
========
2017-12-02 23:02:37 +01:00
2019-08-06 09:30:14 +02:00
Hello world
-----------
2017-12-02 23:02:37 +01:00
2024-06-25 11:28:32 +02:00
.. code-block:: python3
2019-08-06 09:30:14 +02:00
if __name__ == "__main__":
print("Hello, world!")
2024-03-08 23:59:39 +01:00
Files
-----
Links
^^^^^
.. code-block:: python3
os.symlink('target', 'tmp_path')
os.replace('tmp_path', 'path')
2019-08-06 09:30:14 +02:00
Remove
^^^^^^
2017-12-02 23:02:37 +01:00
2024-06-25 11:28:32 +02:00
.. code-block:: python3
2017-12-02 23:02:37 +01:00
2019-08-06 09:30:14 +02:00
import shutil
shutil.rmtree(path)
2017-12-02 23:02:37 +01:00
2024-06-25 11:28:32 +02:00
Log
---
.. code-block:: python3
file_handler = logging.FileHandler('log.txt')
file_handler.setFormatter(formatter)
file_handler.setLevel(logging.INFO)
logger.addHandler(file_handler)
2017-12-02 23:02:37 +01:00
Web
2019-08-06 09:30:14 +02:00
---
Get
^^^
2017-12-02 23:02:37 +01:00
2024-06-25 11:28:32 +02:00
.. code-block:: python3
2017-12-02 23:02:37 +01:00
2019-08-06 09:30:14 +02:00
requests.get(url).content.decode(charset)