更改打开文件访问模式 [英] Change open file access mode

查看:74
本文介绍了更改打开文件访问模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

这篇关于更改打开文件访问模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆