CT320

CT320: Network and System Administration                

Fall 2015                

Python                

CT320: Python                

Python Programming Lab                

The purpose of this assignment is to learn how write basic scripts using the Python programming language.                 

Documentation                

Part 1 — Simple Python Script                

Here is a program named “walk“. Your TA will discuss it.                 

    #! /usr/bin/python3

    import os

    for dirpath, directories, files in os.walk("."):
        for f in files:
            fpath = dirpath + '/' + f
            st = os.stat(fpath)
            mode = st.st_mode & 0o777
            print("%o" % mode, fpath)
  1. What does import do?
  2. What does os.walk return?
  3. What does 0o777 mean?
  4. What does the % operator do?

Part 2 — Run it                

Copy & paste the script, above, to your system (beware of tabs) and make sure that you can execute it.                 

Part 3                

Add code to ignore files that begin with a dot, e.g., .bashrc.                 

Part 4                

Add code to print the file protection bits in the style of ls -l, e.g., -rwxr-xr--                 

Part 5                

Add code to complain, to standard error, if the file is publicly readable, writable, or executable.                 

Part 6                

Add code to not complain (see above) if the file .public exists in the same directory as the file that is publicly readable/writable/executable.                 

Part 7                

Hey, we’re only listing plain files, not directories! Modify your program to also list directories.                 

Part 8                

Show the modification time for the files.                 

Part 9 — Credit                

Show your work to the TA.                 

Modified: 2015-11-20T14:55                 

User: Guest                 

Check: HTML CSS
Edit History Source
Apply to CSU | Contact CSU | Disclaimer | Equal Opportunity
Colorado State University, Fort Collins, CO 80523 USA
© 2015 Colorado State University
CS Building