I need to import function from another file


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

Please help ASAP… My board exams are near.

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.

>Solution :

You can use the __import__() function like:

selection_sort = __import__("selection sort")

and then the file selection sort is imported as selection_sort.

Leave a Reply Cancel reply