+ 1

TypeError

[...] def _saldo(conta): l = Path('Contas/%i.py'%conta) print (l.read_text()) _regs(regsaldo(conta)) verif() menu() def _criarconta(conta,saldo,coment): arquivo = Path('Contas/%i.py'%conta) arquivo.open('w').write('''Conta: %i Saldo: R$%.2f Comentários: %s'''%(conta,saldo,coment)) _regs(regconta(conta)) menu() def menu(): print ("Menu: ") print ("1: Criar uma conta") print ("2: Ver o saldo bancário") print ("3: Verificar registros") print ("0: Sair do programa") teste = int((input('opção: '))) if teste == 1: criarconta() elif teste == 2: saldo() elif teste == 3: regs() elif teste == 0: quit() def regs(): file = Path('registros.py') print(file.read_text()) verif() def regconta(conta): a = print("Conta %s criada "%conta, (time.strftime("%d %m %Y %H:%M:%S"))) def regsaldo(conta): a = print("Saldo verificado conta %s,"%conta, (time.strftime("%d %m %Y %H:%M:%S"))) def _regs(newreg): file = Path('registros.py') file.write_text(file.read_text + """ %s"""%newreg) #TypeError #TypeError: unsupported operand type(s) for +: 'method' and 'str' print("Registro adicionado!") menu() menu()

28th May 2017, 5:44 AM
Thomas Caio Dias
Thomas Caio Dias - avatar
1 Antwort
+ 7
file.readtext() is a method ( function associated to an object ), so you need to explicitly call it by appending parenthesis ( rounded brackets ) to it, else you tell Python to concatenate the method itself rather than the returned value ( expected to be string type )...
28th May 2017, 9:49 AM
visph
visph - avatar