Import own .py files in anaconda spyder

后端 未结 5 1649
梦毁少年i
梦毁少年i 2021-02-14 16:21

I\'ve written my own mail.py module in spider (anaconda). I want to import this py file in other python (spider) files just by \'import mail\'

I searched on the internet

5条回答
  •  心在旅途
    2021-02-14 16:41

    To import any python script, it should exist in the PYTHONPATH. You can check this with the following code:

    import sys
    print sys.path
    

    To import your Python script:

    1. Put both the scripts (main and the imported python script) in the same directory.
    2. Add the location of the file to be imported to the sys.path.

    For example, if the script is located as '/location/to/file/script.py':

     import sys
     sys.path.append('/location/to/file/')
     import script
    

提交回复
热议问题