Q:

How do I import a variable from outside my class?

Simplest way I can describe my problem:
I have a list generated from a separate function outside of my main class. I need to use this same list in a method in my class, but I don't know how to import the list so I can use it in my class.
Both the separate function and class are in the same file, and I cannot instead write that function in my class.
How would I be able to use this list within my class?

A:

You have multiple ways to go about this.
1. Initialize the class with your list.
class Test(object):
    def __init__(self, array):
        self.array = array

    def func(self):
        print(self.array)

array = [1, 2, 3]
t = Test(array)
t.func() # > [1, 2, 3]

2. Global Scope
class Test(object):
    def func(self):
        print(array)

array = [1, 2, 3]
t = Test()
t.func() # > [1, 2, 3]

3. Adding to Class Scope
class Test(object):
    def func(self):
        print(self.array)

array = [1, 2, 3]
t = Test()
t.array = array
t.func() # > [1, 2, 3]

All of these have drawbacks, however. 

Every class must be initialized with an array.
If array is modified outside, it is modified inside the class.
Similar to #1, but array is not initialized with the class. 

Proper object-oriented programming calls for you to do #1, as you explicitly define the variables and context of the objects. It also creates the pretext for you to write functions relating to the passing variables within that object. 

