How do you import a file in python with spaces in the name?

前端 未结 4 1744
鱼传尺愫
鱼传尺愫 2020-11-27 17:09

Do I have to take out all the spaces in the file name to import it, or is there some way of telling import that there are spaces?

4条回答
  •  忘掉有多难
    2020-11-27 17:30

    If you want to do something like from foo_bar import * (but with a space instead of an underscore), you can use execfile (docs here):

    execfile("foo bar.py")
    

    though it's better practice to avoid spaces in source file names.

提交回复
热议问题