Domanda

Please have a look at this snippet:

import xlrd,spss
from xlrd import open_workbook
wb=open_workbook('C:/temp/testbook.xls')
sheetnames=[]
for s in wb.sheets():
   sheetnames.append(s.name)

Why should I write "wb.sheets()" instead of "wb.sheets"? And why is it "s.name" instead of "s.name()"?

I often use empty braces when I'm not supposed to and the other way around. Could anybody tell me what they mean and when I should (not) use them?

È stato utile?

Soluzione

The () are necessary when the attribute (sheets) is a function you with to call. The () should not be used when the attribute is a value want to use directly rather than make a call on.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top