1

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?

asked May 29, 2015 at 9:24
1
  • dmabc only exists inside abcp, so you can't access it from other modules. If you need to, do something like pabc = abc.abcp(dm). Commented May 29, 2015 at 9:29

1 Answer 1

1

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 May 29, 2015 at 9:29
Sign up to request clarification or add additional context in comments.

2 Comments

So i have to print in that file instead try to import variable?
You can also print it inside abc.py, but the only way to access it in main.py would be to store the return value of the method. So, printing works in both modules but importing does not work since it's a local variable that only exists in abc.py and you cannot access it from main.py.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.