Why this compile error?

J

Jimbo

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:
Expected an indented block

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()
 
B

Bruno Desthuilliers

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:
Expected an indented block
Code:
[/QUOTE]
(snip)
# Main program loop
def main():
programEnd = False;

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

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.
 
U

Ulrich Eckhardt

Jimbo said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,471
Messages
2,571,831
Members
48,802
Latest member
shadowoftheunknown
Top