Herramientas de usuario

Herramientas del sitio


wiki2:python:basic

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:basic [2020/04/24 11:35]
root [Implementar tu propio Context Manager]
wiki2:python:basic [2021/09/12 14:16] (actual)
Línea 101: Línea 101:
 <​code>​ <​code>​
 cwd = os.getcwd() cwd = os.getcwd()
-</​code>​ 
- 
-File name from a path: 
-<​code>​ 
-os.path.basename(value) 
 </​code>​ </​code>​
  
Línea 118: Línea 113:
 </​code>​ </​code>​
  
-Get the absolute path:+''​os.path.abspath'': ​Get the absolute path:
 <​code>​ <​code>​
 os.path.abspath(the_relative_path) os.path.abspath(the_relative_path)
 +</​code>​
 +
 +''​os.path.dirname'':​ The parent path of the folder\file:​
 +<​code>​
 +print(root)
 +print(os.path.dirname(root))
 +/​home/​alfred/​Desktop/​presentesNOW/​ReDesktop-SUBJECTS/​Kibbutz
 +/​home/​alfred/​Desktop/​presentesNOW/​ReDesktop-SUBJECTS
 +</​code>​
 +
 +''​os.path.basename'':​ The file\folder name:
 +<​code>​
 +print(root)
 +print(os.path.basename(root))
 +/​home/​alfred/​Desktop/​presentesNOW/​ReDesktop-SUBJECTS/​Kibbutz
 +Kibbutz
 </​code>​ </​code>​
 ===== Implementar tu propio Context Manager ===== ===== Implementar tu propio Context Manager =====
Línea 214: Línea 225:
 </​code>​ </​code>​
  
 +
 +===== SETS =====
 +<code python>
 +>>>​ my_set = set("​patata"​)
 +>>>​ my_set
 +{'​p',​ '​t',​ '​a'​}
 +</​code>​
 +<code python>
 +>>>​ united_set = first_set.union(second_set)
 +>>>​ united_set
 +{'​two',​ '​banana',​ '​three',​ '​peach',​ '​orange',​ '​one'​}
 +...
 +>>>​ first_set = {'​one',​ '​two',​ '​three'​}
 +>>>​ second_set = {'​orange',​ '​banana',​ '​peach',​ '​one'​}
 +>>>​ first_set.intersection(second_set)
 +{'​one'​}
 +...
 +>>>​ first_set = {'​one',​ '​two',​ '​three'​}
 +>>>​ second_set = {'​three',​ '​four',​ '​one'​}
 +>>>​ first_set.difference(second_set)
 +{'​two'​}
 +>>>​ second_set.difference(first_set)
 +{'​four'​}
 +</​code>​
wiki2/python/basic.1587728125.txt.gz · Última modificación: 2020/05/09 09:24 (editor externo)