Python import variable from file
Question: i have a this 2 file: main.py and abc.py

main.py is:

    
    
    dm = [100, 200, 300]
    import abc
    abc.abcp(dm)
    from abc import *
    pabc = abc.dmabc
    print pabc
    

abc.py is:

    
    
    def abcp(dm):
        dmabc = list(dm)
        dmabc[0] -= 50
        print dmabc
        return dmabc
    

The error is: pabc = abc.dmabc (AttributeError: 'module' object has no
attribute dmabc)

if i write:

    
    
    from abc import abcp
    pabc = abc.dmabc
    print pabc
    

The error is: from abc import abcp (ImportError: cannot import name bmf)

if i write:

    
    
    from abc import abcp
    from abcp import dmabc
    pabc = abc.dmabc
    print pabc
    

The error is: from abpc import dmabc (ImportError: No module named abpc)

So how can i import dmabc variable from abc.py file?


Answer: You cannot access the variable `dmabc` because it's a local variable in
`abc.py`.

The best way would be to **store the return value** when calling `abc.dmabc`:

`main.py`:

    
    
    dm = [100, 200, 300]
    import abc
    pabc = abc.abcp(dm)
    print pabc
    

