Created
March 2, 2021 00:10
-
-
Save renzon/8397f43554236b9e2d823751aa764b7f to your computer and use it in GitHub Desktop.
Como pegar um arquivo via caminho relativo a partir de um módulo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from pathlib import Path | |
def main(): | |
caminho_do_arquivo = Path(__file__) | |
caminho_do_arquivo = caminho_do_arquivo / '..' / '..' / 'templates' / 'template.txt' | |
print(caminho_do_arquivo.resolve()) | |
print(caminho_do_arquivo) | |
with open(caminho_do_arquivo.resolve(), 'r', encoding='utf8') as arquivo: | |
for numero_da_linha, linha in enumerate(arquivo): | |
print(numero_da_linha, linha) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment