Ruben Guevara
Ruben Guevara

Reputation: 57

How to concat a path + filename in python?

I am trying to write a function in Python, that concatenates path + filename:

import os 

ruta_proyecto = os.path.dirname(os.path.abspath(__file__))

def ejecutar_sql(archivo, parametro):
    sp.ejecutar_archivo(f"{ruta_proyecto}{archivo}", parametro)

But if I try to add "/ invert* " in the function, it returns an error.

How can I concatenate {ruta_proyecto} + "/ invert"* + {archivo}.

Upvotes: 1

Views: 765

Answers (1)

Ruben Guevara
Ruben Guevara

Reputation: 57

Thanks to the comments of Barmar and Olvin Roght, I have resolved the problem. This is the answer:

def ejecutar_sql(archivo, parametro):
     sp.ejecutar_archivo(os.path.join(os.path.dirname(os.path.abspath(__file__)),f'{archivo}' ), parametro)

Upvotes: 2

Related Questions