import
os
import
stat
filename
=
"file.txt"
fd
=
os.
open
(filename, os.O_RDWR)
mode
=
oct
(os.stat(fd).st_mode)[
-
3
:]
print
(
"Current numeric mode of the file (octal notation):"
, mode)
mode
=
0o777
os.fchmod(fd, mode)
print
(
"\nFile mode changed successfully"
)
mode
=
oct
(os.stat(fd).st_mode)[
-
3
:]
print
(
"Current numeric mode of the file (octal notation):"
, mode)
mode
=
stat.S_IRWXU
os.fchmod(fd, mode)
print
(
"\nFile mode changed successfully"
)
print
(
"Now, File can be read, write and executed by owner only"
)
mode
=
oct
(os.stat(fd).st_mode)[
-
3
:]
print
(
"Current numeric mode of the file (octal notation):"
, mode)
mode
=
stat.S_IRWXU | stat.S_IRGRP
os.fchmod(fd, mode)
print
(
"\nFile mode changed successfully"
)
print
("Now,
File
can be read, write
and
executed \
by owner but can be read by group")
mode
=
oct
(os.stat(fd).st_mode)[
-
3
:]
print
(
"Current numeric mode of the file (octal notation):"
, mode)
os.close(fd)