0

Why am I am getting this error message when I run my code?

AttributeError: 'Workbook' object has no attribute 'get' using xlutils

My code is for a kind of questions and answers and I need to write those answers into Excel. The questions are written in Portuguese but I don't believe makes any important difference..

My Code

from xlutils.copy import copy
import xlwt
import xlrd
nome = input('Fale seu nome: ')
idade = input('Qual a sua idade? ')
qe = 0
q = 2
wb = xlrd.open_workbook("Tabela de desempenho.xls")
wb_copy = copy(wb)
wb_copy.get.sheet(0)

print("Olá ", nome, "Vamos começar o teste.")
print("")
p1 = int(input("Qual é o valor de 2+2? "))
if p1 == 4:
    print("Você acertou!")
p1 = True
else:
    p1 = False

if p1 == False:
    print("Reprovado")
else:
    print("Aprovado!")

p2 = str(input("Qual o nome da instituição? (APENAS SIGLA)"))

if p2 == "APAE":
    print("Correto")
    p2 = True
else:
    p2 = False

if p2 == False:
    print("errado")
else:
    print("Pelo certo")

if p1 == True:
    qe += 1
else:
    qe += 0

if p2 == True:
    qe += 1
else:
    qe + 0

porc = qe / q * 100

print("Seu desempenho foi: ", porc, "%")

if porc == 100:
    print("Você está entre os mais adaptados!")
elif porc == 50:
    print("Você está na metade, quase lá!")
else:
    print("burrokkkkkkkkkkkkkkkkkkkkkk")
w_sheet.write(0,0,'Nome')
w_sheet.write(0,1,'Idade')
w_sheet.write(0,2,'Desempenho')
w_sheet.write(1,0, nome)
w_sheet.write(1,1, idade)
w_sheet.write(1,2, porc)
wb.save("Tabela de desempenho.xls")
jwpfox
  • 5,124
  • 11
  • 45
  • 42
PedroH
  • 1
  • The error message tells you what the problem is. You are creating an object using `copy` from `xlutils` at this line `wb_copy = copy(wb)'. Then you try to access a `get` method on that object on this line `wb_copy.get.sheet(0)` but `xlutils` does not provide a `get` method. – jwpfox Apr 10 '18 at 23:27
  • What can i use to edit an existing file? – PedroH Apr 11 '18 at 08:31
  • A text editor is the usual choice. – jwpfox Apr 11 '18 at 08:34
  • so there is no way to edit an existing excel file using python? – PedroH Apr 11 '18 at 10:50
  • Oh that file - my crystal ball must be faulty - not reading your mind at a distance very well - Yes you can edit an existing Excel sheet using Python - Let me google that for you https://stackoverflow.com/questions/26957831/edit-existing-excel-workbooks-and-sheets-with-xlrd-and-xlwt – jwpfox Apr 12 '18 at 14:13

0 Answers0