Criando arquivos com Python + Context Manager with
This commit is contained in:
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"window.zoomLevel": 1,
|
"window.zoomLevel": 1,
|
||||||
"editor.fontSize": 26,
|
"editor.fontSize": 26,
|
||||||
"editor.hover.enabled": false,
|
"editor.hover.enabled": true,
|
||||||
"workbench.startupEditor": "none",
|
"workbench.startupEditor": "none",
|
||||||
"explorer.compactFolders": false,
|
"explorer.compactFolders": false,
|
||||||
"terminal.integrated.fontSize": 24,
|
"terminal.integrated.fontSize": 24,
|
||||||
|
|||||||
28
aula116.py
Normal file
28
aula116.py
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
# Criando arquivos com Python + Context Manager with
|
||||||
|
# Usamos a função open para abrir
|
||||||
|
# um arquivo em Python (ele pode ou não existir)
|
||||||
|
# Modos:
|
||||||
|
# r (leitura), w (escrita), x (para criação)
|
||||||
|
# a (escreve ao final), b (binário)
|
||||||
|
# t (modo texto), + (leitura e escrita)
|
||||||
|
# Context manager - with (abre e fecha)
|
||||||
|
# Métodos úteis
|
||||||
|
# write, read (escrever e ler)
|
||||||
|
# writelines (escrever várias linhas)
|
||||||
|
# seek (move o cursor)
|
||||||
|
# readline (ler linha)
|
||||||
|
# readlines (ler linhas)
|
||||||
|
# Vamos falar mais sobre o módulo os, mas:
|
||||||
|
# os.remove ou unlink - apaga o arquivo
|
||||||
|
# os.rename - troca o nome ou move o arquivo
|
||||||
|
# Vamos falar mais sobre o módulo json, mas:
|
||||||
|
# json.dump = Gera um arquivo json
|
||||||
|
# json.load
|
||||||
|
caminho_arquivo = 'aula116.txt'
|
||||||
|
|
||||||
|
# arquivo = open(caminho_arquivo, 'w')
|
||||||
|
# #
|
||||||
|
# arquivo.close()
|
||||||
|
with open(caminho_arquivo, 'w') as arquivo:
|
||||||
|
print('Olá mundo')
|
||||||
|
print('Arquivo vai ser fechado')
|
||||||
0
aula116.txt
Normal file
0
aula116.txt
Normal file
Reference in New Issue
Block a user