Why does my python not add current working directory to the path?

前端 未结 2 1664
情歌与酒
情歌与酒 2020-12-13 18:07

I keep seeing sites mentioning that the directory that you execute \'python \' get added to the python path. For example on http://www.stereoplex.com/blog/understanding-impo

相关标签:
2条回答
  • 2020-12-13 18:27

    It is the script's directory that is added, not the current directory. If you turn inner_folder/ into a package then you can use python -m inner_folder.myscript in order to run the script while having app/ added to sys.path.

    0 讨论(0)
  • 2020-12-13 18:37

    Whether or not the current directory is in sys.path, import statements usually look like:

    import mymodule
    

    The code you wrote looks like:

    import 'mymodule.py'
    
    0 讨论(0)
提交回复
热议问题