drwxr-xr-x 10 mst staff 320 Sep 18 14:58 Sites
drwxr-xr-x 2 mst staff 64 May 28 2017 VirtualBox VMs
-rw-r--r-- 1 mst staff 633 Dec 11 2019 balance.pl
drwxr-xr-x 4 mst staff 128 Oct 11 2014 bin
-rw-r--r-- 1 mst staff 473 Dec 13 2019 bitshift.py
For this problem, we are mainly concerned with the set of access permissions, which appears at the beginning of the line for each file or directory. Directories have a "d" at the beginning of their permissions list; files have a dash ("-") at the beginning of their permissions list instead. In the example above, "Sites", "VirtualBox VMs", and "bin" are directories, while the other lines/entries are files.
The list of permissions is a ten-character sequence: the first character indicates whether this item is a file or a directory, while the remaining nine characters indicate permitted actions (read, write, and execute, in that order) for three user types ("owner", "group", and "world", respectively). A letter indicates that the current category of user has that specific type of permission; dashes indicate that the current category of user does not have that type of permission. For example, "rw-" indicates that a particular category of user can read and write (modify) a particular file, but cannot execute it.
As a more complete example, the "bin" directory listed above has the permissions drwxr-xr-x. Translated:
In the code cell below, write some Python code that reads a single line of input from the user, corresponding to a single line of output from the ls command, in the format shown above.
Hint: The rfind() command may be useful here. Assume that the file or directory name DOES NOT contain any spaces!
For example, given the following string input:
-rw-r--r-- 1 mst staff 473 Dec 13 2019 bitshift.py
your code should produce the following (exact) output:
bitshift.py is a file
Group members have read permission
and nothing else.
Below is a screen shot of the python program to check indentation. Comments are given on every line explaining the code. Below is the output of the program: Output 1: Output 2: Below is the code to copy: #CODE STARTS HERE----------------
#Enter input here inp = "-rw-r--r-- 1 mst staff 473 Dec 13 2019 bitshift.py" print("Input: ", inp,"\n") #Printing the input for reference #Extract name by spliting the string by spaces and taking the last word name = inp.split()[-1] #Extract the permession by splitting the string by spaces and taking the first part permession = inp.split()[0] #Group permession is the 5-7 characters in "permession" string group = permession[4:7] if permession[0] == 'd': #Check if directory or file print(name,"is a directory") else: print(name,"is a file") if 'r' in group: #Check for read permession print("Group members have read permission") if 'w' in group: #Check for write permession print("Group members have write permission") if 'x' in group: #Check for execute permession print("Group members have execute permission") #CODE ENDS HERE-----------------
Get Answers For Free
Most questions answered within 1 hours.