如何使用 python 访问 Tableau 2020.2 中的 bin 目录并使用 Tableau 实用程序命令行自动更新数据连接

How to access the bin directory in Tableau 2020.2 using python and automate data connection update using tableau utility command line

我想写一个 python 脚本并 运行 它在命令行中。该脚本应该转到 tableau 2020.2 文件夹中的 bin 目录和 运行 这样的命令

tableau refreshextract --server "Tableau server" --username soroush --password "password" --site "site id" --project "project name" --datasource "DS name" --original-file "file address"

并根据用户提供的名称列表更新数据源名称。

我尝试使用



import os
from pathlib import Path

def main():
  os.chdir("C:\Program Files\Tableau\Tableau 2020.2\bin")
  print(lst)       
      
 
if __name__ == "__main__":
    main()


转到目录和 运行 画面实用程序命令。它给出了这个错误

OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: 'C:\Program Files\Tableau\Tableau 2020.2\x08in'

。所以我想 bin 中有二进制文件并且 Windows 不允许 python 访问它是有原因的。

如果有人指出正确的方向,我将不胜感激。

我知道这个问题对你们中的某些人来说可能听起来很愚蠢,但我没有了解这些东西所需的背景知识。

转义符'\'需要转义

os.chdir("C:\Program Files\Tableau\Tableau 2020.2\bin")

或者,可以使用原始字符串。

os.chdir(r"C:\Program Files\Tableau\Tableau 2020.2\bin")