Ask Your Question

Oshio's profile - activity

2025-02-24 15:46:18 +0200 received badge  Famous Question (source)
2023-07-31 21:23:05 +0200 received badge  Notable Question (source)
2021-12-17 15:35:47 +0200 received badge  Nice Question (source)
2021-12-17 15:35:41 +0200 received badge  Popular Question (source)
2021-01-27 13:19:04 +0200 received badge  Student (source)
2020-11-03 19:14:13 +0200 asked a question Creating a file for user defined functions using JupyterLab environment.

I want to create a function in a separate file, and use that function in another one. Here is the example:

#my_file.ipynb

def my_function(n):
    return n*2

#main.ipnyb

attach('my_file.ipynb')
my_function(2)

But when doing this at the JupyterLab I receive the following erros:

(1) ValueError: unknown file extension '.ipynb' for load or attach (supported extensions: .py, .pyx, .sage, .spyx, .f, .f90, .m)

(2) NameError: name 'my_function' is not defined

This method seems to work for .sage files, but is not working for '.ipynb'.

There is some way to accomplish the result demonstrated through my example using only JupyterLab environment?