Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@renzon
Created March 2, 2021 00:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renzon/8397f43554236b9e2d823751aa764b7f to your computer and use it in GitHub Desktop.
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
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