0

this doesnt work when the file is in the same directory as the .py file.

def get_colocations(filename):
           sentences = open(filename).read().split("\n")
           colocations = []
          for sent in sentences:
                colocations.append(sent)
                return colocations

def main():
    get_colocations("colocations.txt")
    print "Colocations are",colocations

Can anyone help????????

2
Contributors
3
Replies
5
Views
11 Years
Discussion Span
Last Post by girish_sahani
0

Indentations are the bread and butter of Python. Yours are all messed up! Did you mix tabs and spaces in your code? Avoid the mix!

This is corrected code:

def get_colocations(filename):
    sentences = open(filename).read().split("\n")
    colocations = []
    for sent in sentences:
        colocations.append(sent)
    return colocations

def main():
    colocations = get_colocations("colocations.txt")  # !!!!!!!!!
    print "Colocations are",colocations

main()
0

thanks a lot bumsfield....i need to indent my whole program :(
EDIT:i tried the above code but it doesnt work..the program compiles but doesnt return the colocations list...the colocations.txt file is in the same directory as this file..what could be the error?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.