python - How to store words read from a file into a list -


apologies basic question new programming language. found similar questions cannot making them work specific case.

my aim read words txt file (with more lines, each word separated space), store them list , print list check doing.

the following code seems work in terms of printing single words, apparently not storing them (or not able access list).

import os  def main():     read_text(dir_path)  def read_text(file_name):     file_data = []     text_file = open(file_name,"r")      word in text_file.read().split():         print(word)         file_data.append(word)      text_file.close()     return file_data          if __name__ == "__main__":     main() 

what doing wrong? suggestions.

if want store data list further use, need retrieve list read_text method returns:

def main():     resultlist = read_text(dir_path) # store list     # use it... 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -