0
def exportTextList(fileInput, wordList):
    fileOpen = open(fileInput)
    for line in fileOpen:
        line = line.rstrip("\n\r")
        lineList = line.split()
        wordList = wordList + lineList
    return wordList
        
def main():
    fileInput = 'PlayerNames.txt'
    wordList=[]
    exportTextList(fileInput, wordList)
    print wordList

My code summary:
I'm taking a txt file, playernames, and i'm stripping all of the line breaks and creating a list of each word in the file.
If i print wordList before I return it, I get the correct print out
But when I try to return it, and then print word list after in the main function, it just prints a blank list.

Anybody know what's going on?

Thanks in advance

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by richieking
0

Try this first:

def main():
    fileInput = 'PlayerNames.txt'
    wordList=[]
    print exportTextList(fileInput, wordList)   ## <-----

and then see the "gc_counter" function here.

Edited by woooee: n/a

0

Yep woooee

That is it.
Spacemanspiff92 you heard him right.

The wordlist is blank cos the list wordlist got nothing to do with the wordlist in the exportT~ method.

;)

Edited by richieking: n/a

0

also if you are taking in list as methos arg.

its better you provide the arg as list.
like....

def foo(file_name, *word_list):
      #bla bla bla

This the wordlist is auto a list container.

;)

This topic has been dead for over six months. 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.