Created
August 15, 2023 15:37
-
-
Save tiagodavi70/d019d8720466547a069b736a7da21d28 to your computer and use it in GitHub Desktop.
This file contains 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
# 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