Herramientas de usuario

Herramientas del sitio


wiki2:python:notes

Diferencias

Muestra las diferencias entre dos versiones de la página.

Enlace a la vista de comparación

Ambos lados, revisión anterior Revisión previa
Próxima revisión
Revisión previa
wiki2:python:notes [2020/08/27 13:06]
alfred [Libraries]
wiki2:python:notes [2022/01/15 08:41] (actual)
Línea 163: Línea 163:
 </​code>​ </​code>​
 ===== Notes ===== ===== Notes =====
 +==== Install a new version of python ====
  
 To install a new version of python do: To install a new version of python do:
 <​code>​ <​code>​
 sudo apt-get install python3.8 python3.8-dev python3.8-distutils python3.8-venv sudo apt-get install python3.8 python3.8-dev python3.8-distutils python3.8-venv
 +</​code>​
 +
 +==== try\except\finally perks ====
 +
 +This code...
 +<code python>
 +def should_rise(flag):​
 +    if flag:
 +        raise Exception()
 +
 +def my_function(flag):​
 +    try:
 +        should_rise(flag)
 +        print("​1"​)
 +        return "​1"​
 +    except:
 +        print("​2"​)
 +        return "​2"​
 +    finally:
 +        print("​3"​)
 +        return "​3"​
 +
 +
 +print("​f",​ my_function(False))
 +print("​---"​)
 +print("​f",​ my_function(True))
 +</​code>​
 +
 +Prints:
 +<​code>​
 +1
 +3
 +f 3
 +---
 +2
 +3
 +f 3
 +</​code>​
 +
 +==== Install package for the user ====
 +<​code>​
 +pip install --user mypy
 +</​code>​
 +
 +Executables are found in ''​~/​.local/​bin''​ so you can do the next:
 +<​code>​
 +export PATH="​$PATH:​$HOME/​.poetry/​bin:​$HOME/​bin:​$HOME/​.local/​bin"​
 </​code>​ </​code>​
wiki2/python/notes.1598533578.txt.gz · Última modificación: 2020/08/27 14:06 (editor externo)