Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Utilidad que valida la variable de entorno PATH y aquellas variables de entorno con las que está relacionado
import os, re
def evalua(matchobj):
textoAnterior =
llave = textoAnterior[1 : len(textoAnterior) - 1]
if llave in os.environ:
return os.environ[llave]
return textoAnterior
def validaRutas(texto):
p = re.compile('%.*%')
for ruta in texto.split(";"):
rutaCompleta = p.sub(evalua, ruta)
yield ruta, os.path.exists(rutaCompleta)
if __name__ == "__main__":
pathValido = ""
agregado = []
for (ruta, valida) in validaRutas(os.environ['PATH']):
print valida, "\t", ruta
if valida and ruta not in agregado:
pathValido += ruta + ";"
print "\n\n"
print pathValido
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment