Calling variables in another module python
Question: I'm trying to access variables I created in one function inside another module
in Python to plot a graph however, Python can't find them. Heres some example
code:

    
    
    class1:
        def method1
            var1 = []
            var2 = []
        #Do something with var1 and var2
            print var1
            print var2
            return var1,var2
    
    sample = class1()
    sample.method1
    

here is class 2

    
    
     from class1 import *
    
     class number2:
         sample.method1()
    

This does as intended and prints var1 and var2 but I can't call var1 or var2
inside class number 2

FIXED EDIT: Incase anyone else has this issue, I fixed it by importing this
above class two

    
    
      from Module1 import Class1,sample
    

And then inside class2

    
    
          var1,var2 = smaple.method1()
    


Answer: The code you posted is full of syntax errors as Francesco sayed in his
comment. Perhaps you could paste the correct one.

You don't import from a class but from a package or a module. Plus you don't
"call" a variable unless it's a
[callable](http://stackoverflow.com/a/111255/3156085).

In your case you could just have :

**file1.py :**

    
    
    class class1:
        def __init__(self): # In your class's code, self is the current instance (= this for othe languages, it's always the first parameter.)
            self.var = 0
    
        def method1(self):
            print(self.var)
    
    sample = class1()
    

**file2.py :**

    
    
    from file1 import class1, sample
    
    class class2(class1):
        def method2(self):
            self.var += 1
            print(self.var)
    
    v = class2()          # create an instance of class2 that inherits from class1
    v.method1()           # calls method inherited from class1 that prints the var instance variable
    sample.method1()      # same
    print(v.var)          # You can also access it from outside the class definition.
    v.var += 2            # You also can modify it.
    print(v.var)
    v.method2()           # Increment the variable, then print it.
    v.method2()           # same.
    sample.method1()      # Print var from sample.
    #sample.method2()  <--- not possible because sample is an instance of class1 and not of class2
    

Note that to have `method1()` in `class2`, `class2` must inherit from
`class1`. But you can still import variables from other packages/modules.

Note also that `var` is unique for each instance of the class.

