1

How do we import a function from a file, say, 'New File.py' in python in a different file (both being in the same directory)? If it were, say, 'This_thing.py', then we could simply type

from This_thing.py import *fn_name*

What is the format of importing stuff from the file with the said name-type? TL;DR,

from New File.py import fn

doesn't work. What to do?

Yajus Gakhar
  • 15
  • 1
  • 3
  • 4
    Rename the file. A programmer should avoid spaces in filenames wherever possible---certainly in parts that are not end-user-facing, such as source code files. It may or may not be technically possible to work around this particular case (using functional forms of import) but I can almost guarantee that this won't be the last problem that space will cause. – jez Oct 31 '19 at 19:53
  • I understand that, and have saved file names accordingly. But I was just curious whether there was a way to open such files. – Yajus Gakhar Oct 31 '19 at 20:18

0 Answers0