更改打开文件访问模式

编程入门 行业动态 更新时间:2024-10-27 02:29:54
本文介绍了更改打开文件访问模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

打开文件后是否可以更改文件访问模式?

Is it possible to change file access mode after the file has been opened?

f=open(my_file, 'r')

更改f以便能够对其进行写操作,或声明应在通用换行模式下打开该文件?

change f to be able to write to it, or to declare that the file should be opened in universal newline mode?

推荐答案

由于Linux和Windows不支持更改文件描述符的权限.(至少没有posix函数可以更改linux中的打开模式),一旦设置了文件描述符,就无法更改其权限(某些操作系统特定技巧存在,但我不推荐).

Since changing file descriptor's permissions is not supported by Linux nor Windows. (there is no posix function to change open mode in linux at least), it's not possible to change it's permissions once the file descriptor have been set (Some OS specific tricks exists but I wouldn't recommend it).

您需要使用其他权限重新打开它.

You will need to reopen it with other permissions.

更多推荐

更改打开文件访问模式

本文发布于:2023-10-08 13:59:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1472837.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模式   文件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!