1

Intento guardar un archivo .csv, pero este quisiera crearlo en el escritorio, si agrego mi propia ruta si lo hace pero en otra maquina no.

import csv
import os

Data = sys.argv
nombre = Data[1:1] 
Path = os.path

with open(nombre, 'r') as in_file:
    stripped = (line.strip() for line in in_file)
    lines = (line.split(",") for line in stripped if line)
    with open('C:\\Users\\Usuario\\Desktop\\Bitacora.csv', 'w') as out_file:
        writer = csv.writer(out_file)
        writer.writerow(('Respuesta Servidor', 'Tractor', 'Placas', 'Fecha', 'Codigo'))
        writer.writerows(lines)

busque info sobre os.path y ntpath pero no me deja muy en claro la duda

1 respuesta 1

4

Puedes leer la variable de entrono llamada USERPROFILE y construir la ruta hasta el escritorio.

Ejemplo:

import os

path_desktop = os.path.join(os.path.join(os.environ['USERPROFILE']), 'Desktop')
print(path_desktop)
1
  • Vaya me funciono a la perfeccion, muchas gracias!! me pondre a leer mas en la documentacion, porque estare usando mucho las variables el 26 jun. 2020 a las 21:50

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.