I have recently inserted an if statement into some previously working code. I now get an unexpected indent error when I run it on the start of my if statement.
ImpressionsBasedOnWeight = setImpressionsBas开发者_高级运维edOnWeight(setImpressionsBasedOnWeightData)
impressions = data[2]
if reportSuite.RP_UniqueUsers > weighted_impressions:
users = weighted_impressions
else:
users = reportSuite.RP_UniqueUsers
Pages_in_thousands = impressions / 1000
If I remove the indent it fails saying it expects an indent and if I then add the indent it fails saying unexpected indent...
impressions = data[2]
is a simple assigment. There should be no change of the indentation afterwards. So you need to have impressions = ..
and if ..
with the same indentation:
ImpressionsBasedOnWeight = setImpressionsBasedOnWeight(setImpressionsBasedOnWeightData)
impressions = data[2]
if reportSuite.RP_UniqueUsers > weighted_impressions:
users = weighted_impressions
else:
users = reportSuite.RP_UniqueUsers
Pages_in_thousands = impressions / 1000
Also, make sure you're not switching between tabs and spaces for indentation. You can set some indicators to display symbols for tabs, and a good editor should unify indentation when you select the whole code, press Tab
and then Shift+Tab
.
Why to put if with indent?
ImpressionsBasedOnWeight = setImpressionsBasedOnWeight(setImpressionsBasedOnWeightData)
impressions = data[2]
if reportSuite.RP_UniqueUsers > weighted_impressions:
users = weighted_impressions
else:
users = reportSuite.RP_UniqueUsers
Pages_in_thousands = impressions / 1000
精彩评论