Amazing discovery vs Tools Python Project search Paths application

Source: Internet
Author: User

Before, in the absence of an application that found the VS tool Python Project search paths, for example: If the project's file directory is as follows:

maintest/maintest.py you want to use the common/tools.py file, you have to add such code to the code in maintest.py:

Import SYS Import OS  from Import  = Os.path.join (Os.path.dirname (Os.path.dirname (__file__"\common " # Add the directory where tools resides to path Import Tools Print Path Print TOOLS.A

In this case, the code is not concise enough.

Or use the modular idea, the common into a module, put into the maintest/directory, maintest.py file import common.tools module. The project file structure will become as follows:

Maintest

--maintest.py

--common

----tools.py

----__init__.py

This project file structure looks confusing (not human-friendly)

Or you can use Xxx.pth to append the directory where you want to import the module (file), but in this case, your team's small partners unknowingly execute the script will be error ... You must add the same. PTH in the same directory.

Now, just add the parent folder of the file you want to import into search Paths

Well, now maintest/maintest.py want to use common/tools.py directly import module, inside the mechanism has time you can dig into it.

Import SYS Import OS  from Import  = Os.path.join (Os.path.dirname (Os.path.dirname (__file__#path.append ( Parentdir + "\common") # Add the directory where tools resides to pathimport  toolsPrint  path Print TOOLS.A

Amazing discovery vs Tools Python Project search Paths application

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.