python files call other paths

python 的 sys.path.append()

import sys  
sys.path.append('The address of the referenced module') 12

os.path.dirname(path) #return the file path 
os.path.abspath(path) #return the absolute path 
directory: 
BASE_DIR = os.path.dirname( os.path.dirname( os.path.abspath( file ) ) )

Example

#!/usr/bin/env python#-*-coding:utf-8-*-# wanghuiimport os
import sys
BASE_DIR = os.path.dirname( os.path.dirname( os.path.abspath(__file__) ) )

sys.path.append(BASE_DIR)
from conf import settings
from core import main

main.login()123456789101112



Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326690671&siteId=291194637