So,I have a main.py and a file.py
on file.py I have a function(ex:
def s_break(message):
words = message.split(" ")
, and an array words. )
When I import the words array into main.py using: from "filename" import words I receive the array empty. Why?
Thank you!
You need to actually call the s_break function otherwise you'll just get the empty list/array.
test_file.py:
message = 'a sample string this represents'
list_of_words = []
def s_break(message):
words = message.split(" ")
for w in words:
list_of_words.append(w)
s_break(message) # call the function to populate the list
And then in main.py:
from test_file import list_of_words
print list_of_words
Output:
>>> ['a', 'sample', 'string', 'this', 'represents']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With