Hello All,

New to Python,

I keep getting an indentation error after the if (yescheck == todcheck): line. Any suggestions? As far as my python knowledge goes, I've got it correctly aligned, but clearly not.

Could some of you try running this, see if it goes?

import os
yesfile = open('C:\HeavyWeather\sp050518.txt')
todfile = open('C:\HeavyWeather\sp050519.txt')
yesdata = []
toddata = []
for line in yesfile.readlines():
	yesdata.append(line)
for line in todfile.readlines():
	toddata.append(line)	
for position in range(len(yesdata)-1):
	yesline = yesdata[position]
	todline = toddata[position]
	yescheck = yesline.split(",")[1]
	todcheck = todline.split(",")[1]
	if (yescheck == todcheck):
                yesprice = float(yesline.split(",")[2])
                todprice = float(todline.split(",")[2])
                pricechange = todprice - yesprice
                print pricechange
	else:
            print "Mismatch at ", yesline.split(",")[1], ", ", todline.split(",")[1]

Recommended Answers

All 5 Replies

You are commiting one of the cardinal violations in Python when you mix tabs and spaces in your indentations. Many editors do not match the correct amount of spaces with your tabs, now you have a mess on your hand. Please use the customary 4 spaces only, avoid tabs!

When a user enter after setting up the condition the pointer goes to the next line in the interpreter but it don't take the space before print step.
So user need to provide a space after enter to avoid error.
eg,
>>>a=2
>>>if a>3:
----(space need to be added) print"".

definatly indenting error right here

if (yescheck == todcheck):
                yesprice = float(yesline.split(",")[2])
                todprice = float(todline.split(",")[2])
                pricechange = todprice - yesprice
                print pricechange
	else:
            print "Mismatch at ", yesline.split(",")[1], ", ", todline.split(",")[1]

#which you can fix to this

        if (yescheck == todcheck):
            yesprice = float(yesline.split(",")[2])
            todprice = float(todline.split(",")[2])
            pricechange = todprice - yesprice
            print pricechange
	else:
            print "Mismatch at ", yesline.split(",")[1], ", ", todline.split(",")[1]

I don't think the OP is still waiting for the answer after 3 years :)

I think you are correct since the OP only made one post at all.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.