我正在同一网络中的两台服务器(Ubuntu和Windows)之间移动一个.txt文件。 以下代码未显示任何错误,但不起作用:
def transfer_files_task():
source_path = r"/root/airflow/testdoc"
dest_path = f"192.168.xxx.xx\Doc-Share\Logger Output"
filename = r"/test.txt"
filenamew = f"\test.txt"
shutil.copyfile(source_path + filename, dest_path + filenamew)
将您的功能更改为:
一个小的解释:让python格式化您的路径,它将使您避免许多错误。如果不这样做,您必须知道字符串是如何工作的,应该转义哪些字符,如何在linux和windows上格式化路径,等等
另外,关于字符串使用
r
和f
前缀的旁注:r"\tab" == "\\tab"
和print(r"\tab")
给出\tab
,而print("\tab")
给出ab
最后,您可能想查看以下帖子:Cannot copy file from a remote machine using shutil
相关问题 更多 >
编程相关推荐