unable to import python file into another file

13,712

If both files a and a_test are in the same folder, you should be able to call methods from a (even when they're not in sys.path):

a.py

def hello():
    print 'Hello'

a_test.py

from a import *
hello()

Returns 'Hello' if I run a_test.py. Does this minimal example work for you?

Remember certain imports (with names like file) can cause problems if they're already python core modules.

Share:
13,712
Farrukh Faizy
Author by

Farrukh Faizy

A passionate software developer and a keen learner.

Updated on June 28, 2022

Comments

  • Farrukh Faizy
    Farrukh Faizy almost 2 years

    I am basically working with python(beginner) on visual studio and stuck on importing a python file into another python file.I am working on an assignment it has 3 files a , b and test_a while making a function in file 'a' and importing that file into test_a to test a function but didn't get answer
    I tried this line for importing file 'a' in 'test_a' like this but unable to import

    from a import * 
    

    any idea how to import a whole file into another ?