Python3: How to handle relative paths with modules

0

I have the method below:

def get_conteudo_file(filename: str, encoding: str="iso8859-1") -> str:
    filename = os.path.abspath(os.path.join(*filename.split(os.sep)))
    assert os.path.isfile(filename), "Arquivo '{}' indisponível".format(filename)
    with open(filename, encoding=encoding) as f:
        logging.debug('filename: "{}" readed'.format(f.name))
        return f.read()

get_conteudo_file("~/Documents/projeto/me.py", "utf-8")

How to handle this relative path to access the file?

    
asked by anonymous 18.10.2018 / 19:26

0 answers