0

I am using Jupyter notebook with python version 3.6. I have some code written in a separate external.py file that I import, then call a function from this file. This function then calls a function defined in the body of the python notebook. For instance,

import external
def subsequent():
    <some code>
external.func1()

func1 is called successfully but gives error when calling 'subsequent', from within func1. I have tried moving the 'import external' line to be after the definition of 'subsequent'. This did not work either.

Is there a way to reference the calling ipython notebook?

Many thanks

Regards,

Adeel

1
  • Does func1() calls subsequent() function? Commented Nov 1, 2018 at 6:13

1 Answer 1

1

Try lambda function and pass that function as a parameter to func1.

  from external import func1
  subsequent=lambda a : print(a + 10)
  func1(subsequent)

OR

pass the function as a parameter

from external import func1
def subsequent(a):
    print(a + 10)
func1(subsequent)

Cheers :-)

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot, Dulmina. Worked like a charm!

Your Answer

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.