I need to import function from another file

Question:

I know how to import functions from normal files…
but my file name is ‘selection sort’
it contains a space in between
is there a way to import function from these without renaming it

I tried import selection sort and import selection_sort… both didn’t work

I also watched few videos and questions like these but can’t find the solution.

Asked By: Bishwajeet Singh

||

Answers:

You can use the __import__() function like:

selection_sort = __import__("selection sort")

and then the file selection sort is imported as selection_sort.

Answered By: sbottingota

While it is not recommended to have a space in the file name, you could try:

selection_sort = __import__("selection sort")
Answered By: Islam Elbanna