Python import variable from file

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?

Add Comment
1 Answer(s)

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 
Answered on July 16, 2020.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.