文件未使用 python 脚本写入 Windows 上的映射网络驱动器

问题描述 投票:0回答:1

我有一个 python 脚本,它访问 Windows 操作系统上的映射网络驱动器,并在映射位置创建一个要写入的文件。这是要编写的代码。

output_file = f"{output_dirPath}/{directory_name}{output_suffix}"


with open(output_file, 'w') as file:
    file.write("Sample Name\tFilename\tSample Type\tProcessing Setting\tReference\n")
    for path in file_paths:
        file_name = os.path.basename(path)  # Extract the file name from the path
        final_filename = os.path.splitext(file_name)[0]  # Remove the .bam extension
        file.write(f"{final_filename}\t{path}\t{sample_type}\t{processing_setting}\t{reference}\n")

其中,output_dirPath是我正在访问的映射网络驱动器,如下所示

output_dirPath = "//abc/data/lab/Archives/Test/{}".format(directory_name)

目录名称可以是任何包含空格、_ 和 - 的字母数字字符串。

输出后缀为

_template.txt

当我运行此脚本时,代码部分(此处未提及)运行并解压缩文件),但是不会写入文件并给出以下错误。

Traceback (most recent call last):
  File "Template.py", line 76, in <module>
    with open(output_file, 'w') as file:
         ^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '//abc/data/lab/Archives/Test/Output Folder abc 1ef3D00.example/Output Folder abc 1ef3D00.example_bamTemplate.txt'
python unc
1个回答
0
投票
如果文件不存在,则具有模式

open()

(写入)的 
Python 的
'w'
函数将创建该文件,但这仅在指向该文件的目录路径存在时才有效。路径
//abc/data/lab/Archives/Test/Output Folder abc 1ef3D00.example
不得存在。

© www.soinside.com 2019 - 2024. All rights reserved.