Question

python3.8 os.stat number to letter I am currently using os.stat to get file permission in string(rwx),...

python3.8 os.stat number to letter

I am currently using os.stat to get file permission in string(rwx), owner(in letter), group(in letter)

I tried os.state.filemode but it does not work for my python version. Also I cannot find anything at I can change to string for owner and group.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

# to get file permission of os.stat number to string we stat library not os.stat

# to get owner of file we use stat to get user id by st_uid which is a number to get actual username we use pwd library

# to get group of file we use stat to get group id by st_gid which is a number to get actual groupname we use grp library

import os

import stat

import pwd

import grp

f = os.stat(filepath)

permission = stat.filemode(os.st_mode)

owner = pwd.getpwuid(f.st_uid).pw_name
group = grp.getgrgid(f.st_gid).gr_name

Add a comment
Know the answer?
Add Answer to:
python3.8 os.stat number to letter I am currently using os.stat to get file permission in string(rwx),...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. Assume the following struct is declared for the permission list of a file in Linux....

    1. Assume the following struct is declared for the permission list of a file in Linux. Each permission (u or g or o) is represented as an octal. For example, u=7 means rwx, u=5 means r-x. Note: "unsigned char" means a byte, not a character or a letter or a string. typedef struct { unsigned int uid; // owner id unsigned int gid; // group id unsigned char u; // owner's permission unsigned char g; // group's permission unsigned char...

  • I am using C++ Start with the distance.cpp file on the website. Fill in the missing...

    I am using C++ Start with the distance.cpp file on the website. Fill in the missing functions to enable the program to compile and correctly find determine which entered distance is larger. The user can either enter it in meters labeled with an “m”, or in feet and inches labeled with and ' and “. You may not change main(), we will check to ensure it is exactly the same. The meters and inches can be doubles, but the feet...

  • I am having problems with reading a file into an array. This is my code. This...

    I am having problems with reading a file into an array. This is my code. This is what I get when I run my program. But this is my text file I am reading. I tried everything and it seems to be reading in the last digit of the file. I want to read in their names line by line into an array and ultimatly also read in the scores line by line. 1 E/7 Programming Assignment 6.cpp Defines the...

  • 5.Create two files also called file file1 and file2 in testdir_2 Use the ls -lR to show you created the directories 6. Change the permission of the files in the directories below and show their permi...

    5.Create two files also called file file1 and file2 in testdir_2 Use the ls -lR to show you created the directories 6. Change the permission of the files in the directories below and show their permissions testdir/testdir_1/file1 where owner has read and execute permissions testdir/testdir_1/file2 where where owner has read, write and execute permissions. Group has read only permissions 7. Create a directory called newdir/newdir_1/newdir_2 copy the file testdir/testdir_1/file1 to this directory Change the permisions of the file to owner,...

  • Write a program in C using Unix system calls and functions that will change the permissions on a ...

    Write a program in C using Unix system calls and functions that will change the permissions on a file. The executable shall be called “mychmod” and will be executed by: mychmod -u rwx -g rwx -o rwx -U rwx -G rwx -O rwx file1 file2 ... The lowercase options will add permissions while the uppercase options will remove permissions. Each of the switches is optional and should be interpreted as the ones in the Unix command chmod(1), you can review...

  • I am working on java patter. my code read the string and it will get only...

    I am working on java patter. my code read the string and it will get only the numbers. in this case,124,140,130..but i want to get the maximum number. which is 140. I would appreciate any kind of help. This is my code public class questions {    public static void main(String[] args) {        int total=0;        String test="it tookthismuch total time: 124. it tookthismuch total time: 140. it tookthismuch total time: 130. ";              ...

  • C++ please Write a program that reads the following sentences from a file: I am Sam...

    C++ please Write a program that reads the following sentences from a file: I am Sam Sam I am That Sam I am That Sam I am I do not like that Sam I am Do you like green eggs and ham I do not like them But I do like spam! You will first have to create the text file containing the input, separate from your program. Your program should produce two output files: (i) (ii) one with the...

  • I am currently doing homework for my java class and i am getting an error in...

    I am currently doing homework for my java class and i am getting an error in my code. import java.util.Scanner; import java.util.Random; public class contact {       public static void main(String[] args) {        Random Rand = new Random();        Scanner sc = new Scanner(System.in);        System.out.println("welcome to the contact application");        System.out.println();               int die1;        int die2;        int Total;               String choice = "y";...

  • Hello, I am in Physics 102 in college and am currently in a unit on circuits....

    Hello, I am in Physics 102 in college and am currently in a unit on circuits. We are studying voltage, current, resistance, capacitance, etc. The majority of the problems we work on are out of the "Fundamentals of Physics, 9th edition" textbook. I have been using your answers to guide me in my homework, but I would eventually like to be able to have a strategy to conquer these problems on my own. Most of the time I cant figure...

  • Java. Java is a new programming language I am learning, and so far I am a...

    Java. Java is a new programming language I am learning, and so far I am a bit troubled about it. Hopefully, I can explain it right. For my assignment, we have to create a class called Student with three private attributes of Name (String), Grade (int), and CName(String). In the driver class, I am suppose to have a total of 3 objects of type Student. Also, the user have to input the data. My problem is that I can get...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT