0

I'm fairly new to Python. Here's the code in 'file1'

phrases = []
buildWord = ""

file = open("words.txt")
words = file.read()
for i in words:
    if(i == "\n"):
        phrases.append(buildWord)
        buildWord = ""
    else:
        buildWord += i
file.close()

Basically, there's a loop that gets all words in a file called 'words.txt' and appends them into a list called phrases. Now, in 'file2' I would like to simply import this phrases variable to use. Here's the code used in 'file2'

from 'file1' import phrases

This throws an error "no module named, is not a package". Why am I getting this error?

2
  • 2
    You should name your file1 as file1.py and import it like: from file1 import phrases Commented Jun 9, 2020 at 20:50
  • remove the '' from file1 Commented Jun 9, 2020 at 20:50

1 Answer 1

0

Try removing the ' ' from 'file1' and try this: from file1 import phrases

Edit:

Someone in the comment said you should rename your file1 to file1.py. Make sure to do that too :)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.