Open main menu

CDOT Wiki β

Changes

OPS435 Python Lab 3

46 bytes added, 19:32, 2 June 2017
PART 2 - Running System Commands with Subprocess
:#Create the "'''~/ops435/lab3/lab3d.py'''" script. The purpose of this script is to create a Python function that can return the linux system's root directory free space.
:::*The script should have a '''Shebang line'''
:::*The script should '''import subprocess''':::*The script should use the linux command ": '''df -h | grep '/$' | awk '{print $4}'" ''' :::*The script should contain the function called: '''free_space()''':::*The function '''free_space() ''' should return a string which is in '''utf-8 ''' and has newline characters striptstrip
:::*Note: your output may be completely different, the free/available disk space on every computers root directory may be different.
:::2. '''Sample Run 1: ''' <source>
run lab3d.py
9.6G
</source>
:::3. Sample Import 1Run 2 (with import):<source>
import lab3d
 
lab3d.free_space()
'9.6G'
</source>
:::43. Exit the ipython3 shell, download the checking script and check your work. Enter the following commands from the bash shell.<source>
cd ~/ops435/lab3/
pwd #confirm that you are in the right directory
python3 ./CheckLab3.py -f -v lab3d
</source>
:::54. Before proceeding, make certain that you identify any and all errors in lab3d.py. When the checking script tells you everything is OK before proceeding to the next step.
Make notes for all of your observations in your lab log book, and proceed to INVESTIGATION 3.<br><br>
13,420
edits