0

How can I open all the text file within a folder and get a string ? For example this is all the word in a txt file:

HelloWorld 
Hi 
HelloUser. 

I want to get all the word with a Hello in the word and store it in an array.

I want to store it in an array not to return if its true or not.

  • How do you know which part you want? – Stephen Rauch May 20 '18 at 02:37
  • Normally, you want to get a list of filenames—e.g., with `os.listdir`—and then loop over them: `words = []` `for filename in filenames:` `with open(filename) as file:` `for line in file:` `if : words.append()`. – abarnert May 20 '18 at 02:42
  • As a side note, you probably want to store your words in a list. An `array` (whether a stdlib `array.array` or a third-party library like `numpy.array`) is usually use for a large collection of fixed-size values, not a collection of strings you build up one at a time. – abarnert May 20 '18 at 02:44
  • I just want to append all the word that starts with hello in an array – Khristian Morales May 20 '18 at 02:51
  • The one this guy eyllanesc marked as duplicated isn't an answer to my question since it can only print a value. How can I store it in an array? I'm very new to python – Khristian Morales May 20 '18 at 02:52

0 Answers0