python - 如何使目录路径相对,以便我们可以在 Mac 和 Windows 中运行代码
问题描述
我正在使用 Python 打开网络驱动程序。驱动程序路径是绝对的。如何使这个绝对路径动态化,以便我也可以在 Windows 上运行相同的代码?
from selenium import webdriver
driverpath="/Users/abhinavwadhankar/PycharmProjects/PythonAutomationFramework/Drivers/chromedriver-5"
driver = webdriver.Chrome(executable_path=driverpath)
driver.get("http://www.google.com")
print(driver.title)
解决方案
推荐阅读
- ruby-on-rails - 为什么 webpacker:compile 在 javascript_pack_tag 中插入特定的主机名?
- domain-driven-design - 按 id 检索实体引用其他聚合
- c# - 循环遍历类属性并获得不同的值
- python - 将 csv 列的某些值替换为另一个列中的值
- ruby-on-rails - 满足条件后如何自动更新父级?
- bash - 根据索引从数组中删除多个元素
- electron - 如何在我的 Electron 应用程序的客户端代码中导入 Node 模块?
- html - ReactJs - SPA 导航栏
- c - 套接字:连接失败,连接被拒绝
- node.js - npm 不支持 Node.js v10.0.0 但安装了旧版本