1

I have 2 Python files,

one is main.py (main code) and other is source.py (functions).

I import source.py into the main.py and call all the functions defined in source.py.

But when I write a new function at the run time, it will be shown in by the source.py's object but when called it shows an error.

# source.py
def fun1():
    print('India is the best !!!!!!!!!')

    
def fun2():
    print('Delhi is capital of India !!!!!!!!!') 
# main.py

import source
source.fun1()
source.fun2()

This code runs properly.

When I add a new function to the source.py

def fun3():
   print('Modi is India's Prime minister!!!!!!!')

If I import source.py again and call fun3() from main.py, It show the following error :

Traceback (most recent call last): File "", line 1, in AttributeError: module 'source' has no attribute 'fun3'

I want to know how to re-import the source.py so that it uses newly coded function without restarting the IDE I am using.

I am using Visual Studio 2017 for development in python

TIA

Emi OB
  • 2,814
  • 3
  • 13
  • 29

1 Answers1

1

Thanks all of you to for your reply, Problem solved after running following command:

import importlib
importlib.reload(source)
joanis
  • 10,635
  • 14
  • 30
  • 40