python3——跨文件調用模塊


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()

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM