GNU/Linux >> Tutoriales Linux >  >> Linux

¿Cómo usar / (separador de directorio) tanto en Linux como en Windows en Python?

Usar:

import os
print os.sep

para ver cómo se ve el separador en un sistema operativo actual.
En tu código puedes usar:

import os
path = os.path.join('folder_name', 'file_name')

Puede utilizar os.sep:

>>> import os
>>> os.sep
'/'

Usa os.path.join() .Ejemplo:os.path.join(pathfile,"output","log.txt") .

En tu código sería:rootTree.write(os.path.join(pathfile,"output","log.txt"))


Linux
  1. Cómo instalar y usar Flatpak en Linux

  2. Cómo usar Python para consultar WMI (Linux – Windows)

  3. UNIX/Linux:Cómo usar Sticky Bit en directorios y archivos

  4. ¿Cómo puedo definir DIRECTORY_SEPARATOR para las plataformas Windows y Linux?

  5. ¿Qué sistema de archivos usar cuando se usa tanto Windows como Linux?

Cómo usar el comando cd en Linux

Cómo instalar y usar phpMyAdmin en Linux

Cómo instalar y usar Python-Mistune en Linux

Cómo instalar y usar el comando fd en Linux

Cómo instalar y usar Nu Shell en Linux

Cómo instalar y usar el IDE de Thonny Python en Linux