[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Why this compile error?

Jimbo

3/19/2010 9:38:00 AM

Hello

Can you help me figure out why I am getting this compile error with my
program. The error occurs right at the bottom of my code & I have
commented where it occurs.

The error is:
[QUOTE]Expected an indented block[/QUOTE]

[CODE]"""
*Stock Data Builder*
Algorithm:
- Search website for stock
- Get website HTML source code
- Search code for target stock data(price,dividends)
- Add data to text file
"""

import sys

# Functions
def getSource(URL, sourceBuffer):
""" Retrieve HTML source code from websitr URL &
save in sourceBuffer """

return sourceBuffer

def getData(targetData, dataBuffer):
""" Searches the string dataBuffer for the occurence of target
data & returns that whole line """

def writeToFile(textFile, dataBuffer):
""" Writes data in string dataBuffer to text file """

# CHANGE this to try except to catch errors
fileT = open(textFile,'a')
fileT.write(dataBuffer)
return True; # function succeeded

def writeToFile(textFile, dataList):
""" Writes data in List dataList to text file """

# CHANGE this to try except to catch errors
fileT = open(textFile,'a')

for element in dataList:
fileT.write(element)
return True; # function succeeded



# Main program loop
def main():
programEnd = False;

while (programEnd == False):
#ERROR HERE?? - Error="Expected an indented block"
main()[/CODE]
2 Answers

Bruno Desthuilliers

3/19/2010 10:04:00 AM

0

Jimbo a écrit :
> Hello
>
> Can you help me figure out why I am getting this compile error with my
> program. The error occurs right at the bottom of my code & I have
> commented where it occurs.
>
> The error is:
> [QUOTE]Expected an indented block[/QUOTE]
>
> [CODE]
(snip)
> # Main program loop
> def main():
> programEnd = False;
>
> while (programEnd == False):
> #ERROR HERE?? - Error="Expected an indented block"

Indeed. You *need* a stamement in the while block. If you want a noop,
then use the 'pass' statement:

while programEnd == False:
pass


But note that as-is, this will go into an infinite loop.

Ulrich Eckhardt

3/19/2010 10:11:00 AM

0

Jimbo wrote:
> Can you help me figure out why I am getting this compile error with my
> program. The error occurs right at the bottom of my code & I have
> commented where it occurs.
[...]
> def main():
> programEnd = False;
>
> while (programEnd == False):
> #ERROR HERE?? - Error="Expected an indented block"
> main()[/CODE]

Was the comment there before or not? In any case, I believe a comment
doesn't qualify as indented block, if you want to leave the block empty
use 'pass' instead. Also, make sure you don't mix tabs and spaces, which is
also a popular way to confuse Python.

BTW: "while" doesn't need brackets, that's a C-ism. ;)

Cheers!

Uli

--
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932