Skip to content

Instantly share code, notes, and snippets.

@tiagodavi70
Created August 15, 2023 15:37
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 tiagodavi70/d019d8720466547a069b736a7da21d28 to your computer and use it in GitHub Desktop.
Save tiagodavi70/d019d8720466547a069b736a7da21d28 to your computer and use it in GitHub Desktop.
# Abrindo e fechando
arquivo1 = open("arquivo1.txt", "r")
print(arquivo1.read())
arquivo1.close()
with open("arquivo1.txt", "r") as arquivo1:
print(arquivo1.read())
# Escrevendo
with open('arquivo2.txt', 'w') as arq:
texto = 'Coisas novas\nno arquivo'
arq.write(texto)
lista = ["a", "b"]
with open('arquivo3.txt', 'w') as arq:
arq.write(str(lista))
with open('arquivo3.txt', 'r') as arq:
print(eval(arq.read()))
import os
# Criar uma pasta
os.mkdir("nova_pasta")
os.makedirs("caminho/do/novo/diretorio")
# Listar os arquivos do diretório
conteudo_diretorio = os.listdir(".")
print("Conteúdo do diretório:", conteudo_diretorio)
# Verificando existência de arquivo
existe = os.path.exists("arquivo2.txt")
print("Existe:", existe)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment