gpt4 book ai didi

python - 重写写保护文件

转载 作者:太空宇宙 更新时间:2023-11-04 10:34:52 24 4
gpt4 key购买 nike

如果需要,文件每 4 小时更新一次新信息 - 即是否已为该特定文件处理任何新信息(文件对应于人)。

我正在运行此命令以将我的 .stp 文件(每 4 小时更新一次)转换为 .xml 文件。

rule convert_waveform_stp:
input: '/data01/stpfiles/{file}.Stp'
output: '/data01/workspace/bm_data/xmlfiles/{file}.xml'
shell:
'''
mono /data01/workspace/bm_software/convert.exe {input} -o {output}
'''

我的脚本在 Snakemake(基于 python)中,但我正在通过 shell 命令运行 convert.exe

我在已经使用 convert.exe 处理过的文件上遇到错误。它们由 convert.exe 保存为写保护,并且没有选项可以在可执行文件本身中绕过它。

错误信息:

ProtectedOutputException in line 14 of /home/Snakefile:
Write-protected output files for rule convert_waveform_stp:
/data01/workspace/bm_data/xmlfiles/PID_1234567.xml

我仍然希望它们被写保护,但也希望能够根据需要更新它们。

我可以在我的 shell 命令中添加一些东西来覆盖写保护的文件吗?

最佳答案

看一下os标准库包:

https://docs.python.org/3.5/library/os.html?highlight=chmod#os.chmod

它允许 chmod,但有以下警告:

Although Windows supports chmod(), you can only set the file’s read-only flag with it (via the stat.S_IWRITE and stat.S_IREAD constants or a corresponding integer value). All other bits are ignored.

@VickiT05,我以为你想在 python 中使用它。试试这个:

检查原始文件权限

ls -l [your file name]

stat -c %a [your file name]

将保护改为with

chmod 777 [your file name]

改回原始文件模式或任何你想要的模式

chmod [original file protection mode] [your file name]

关于python - 重写写保护文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38100441/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com