Python Forum
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
indentation tips
#4
Thanks, I will have to try to keep everything simple, break things down into smaller steps. I had a problem with putting an 'if clause' in my calculate % scores routine. I could not get the indentation to work, so I put this before that step:

# avoid None values in any relevant cells
for sheet in sourceSheetNames:
	sourceFileActiveSheet = sourceFile[sheet]
	maxCol = sourceFileActiveSheet.max_column
	maxRow = sourceFileActiveSheet.max_row
	for colNum in range(11, maxCol + 1, 3):
	    for rowNum in range(4, maxRow +1):
		    if sourceFileActiveSheet.cell(row=rowNum, column=colNum).value == None:
			    sourceFileActiveSheet.cell(row=rowNum, column=colNum, value=0)
This avoids any errors like this

Quote:Traceback (most recent call last):
File "./calculate%scores.py", line 98, in <module>
totalAttendance = totalAttendance + addScore
TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'
Reply


Messages In This Thread
indentation tips - by Pedroski55 - Sep-14-2018, 09:35 AM
RE: indentation tips - by Gribouillis - Sep-14-2018, 10:11 AM
RE: indentation tips - by gruntfutuk - Sep-14-2018, 01:24 PM
RE: indentation tips - by Pedroski55 - Sep-15-2018, 10:55 PM
RE: indentation tips - by Gribouillis - Sep-16-2018, 10:21 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Any tips to how to find out values? nevlindan 1 743 Apr-27-2023, 09:14 PM
Last Post: deanhystad
  coding improvement tips vaisesumit29 1 1,846 Mar-10-2019, 05:09 PM
Last Post: stullis
  Tips for CLI program with Keybinding system pedropessoa 2 2,617 Nov-21-2018, 09:59 AM
Last Post: Gribouillis
  Organizing tips Demini 1 2,244 Feb-10-2018, 05:32 AM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020