Advertisement
tomateblue

Escreve_e_LeArquivo.py

Dec 2nd, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3.  
  4. def Criar_e_fechar(opcao,namefile,txt):
  5.  
  6.   if opcao == 1:
  7.      print "Arquivo Criado Com Sucesso ! ", namefile
  8.      arquivo = open(namefile,"w+")
  9.      arquivo.write(txt)
  10.      arquivo.close()
  11.  
  12.   if opcao == 2:
  13.      print "Arquivo Fechado com Sucesso !",namefile
  14.      arquivo = open(namefile,"r")
  15.      texto = arquivo.read()
  16.      print "\tText: [%s]" % texto
  17.      arquivo.close()
  18.  
  19. def menu():
  20.    menu = "0 - sair\n1 -  criar arquivo\n2 - ler arquivo\n: "
  21.    while True:
  22.      n = int(raw_input(menu))
  23.      if  n == 0:
  24.          print "FLWS"
  25.          break
  26.  
  27.      if  n == 1:
  28.          nome_do_arquivo  = raw_input("Nome arquivo: ")
  29.          texto = raw_input("texto: ")
  30.          Criar_e_fechar(1,nome_do_arquivo,texto)
  31.      if  n == 2:
  32.          nome_do_arquivo  = raw_input("Nome arquivo: ")
  33.          Criar_e_fechar(2,nome_do_arquivo,False)
  34.  
  35. menu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement