1

my_main_file.py:

from bfile import bfunc
def fna():
  bfunc(sth)

if __name__ == "__main__":
  fna()

bfile.py:

def bfunc(sth):
  #bla bla..

Error:

name 'bfunc' is not defined

Both files are under same directory

PS: I have tried everythig here Call a function from another file in Python

ishandutta2007
  • 16,676
  • 16
  • 93
  • 129

3 Answers3

1

Add __init__.py python file to your current working directory.So python will treat directory as containing package.You can see documentation here

0

Try

import bfile
def fna():
    bfile.bfunc(sth)
Naveen
  • 770
  • 10
  • 22
0

adding export PYTHONPATH="." to bash_profile solved the issue

ishandutta2007
  • 16,676
  • 16
  • 93
  • 129