1、文件目錄
在test02.py文件中調用test01.py文件中的ceshi()函數
2、參考代碼:
test01:
def ceshi(): from selenium import webdriver option = webdriver.ChromeOptions() option.add_argument('headless') # 靜默模式 # 打開chrome瀏覽器 driver = webdriver.Chrome(chrome_options=option) driver.get("http://www.baidu.com") print(driver.title)
test02參考代碼:
import sys from os.path import dirname, abspath project_path = dirname(dirname(abspath(__file__)) # __file__用於獲取文件所在的路徑,調用os.path下面的abspath(__file__),可以得到文件的絕對路徑
sys.path.append(project_path + '\\0506') from test01 import ceshi ceshi()