384
edits
Changes
no edit summary
</source>
:'''Perform the following steps:'''
:1. [https://ict.senecacollege.ca/~raymonderic.chanbrauer/ops435ops445/labs/lab7/lab7a.py Download] or create the above Pythone script '''lab7a.py''' in your ~/ops445/lab7 directory. :2. [https://ict.senecacollege.ca/~raymonderic.chanbrauer/ops445/labs/lab7/lab7a1.py Download] or create a new Python script named '''lab7a1.py''' in the lab7 directory:<source lang="bash">
cd ~/ops445/lab7
vi ~/ops445/lab7/lab7a1.py
cd ~/ops445/lab7/
pwd #confirm that you are in the right directory
ls CheckLab7.py || wget https://ict.senecacollege.ca/~raymonderic.chanbrauer/ops435ops445/labs/LabCheckScripts/CheckLab7.py
python3 ./CheckLab7.py -f -v lab7a
</source>
cd ~/ops445/lab7/
pwd #confirm that you are in the right directory
ls CheckLab7.py || wget https://ict.senecacollege.ca/~raymonderic.chanbrauer/ops435ops445/labs/LabCheckScripts/CheckLab7.py
python3 ./CheckLab7.py -f -v lab7b
</source>
cd ~/ops445/lab7/
pwd #confirm that you are in the right directory
ls CheckLab7.py || wget https://ict.senecacollege.ca/~raymonderic.chanbrauer/ops435ops445/labs/LabCheckScripts/CheckLab7.py
python3 ./CheckLab7.py -f -v lab7c
</source>
</source>
: Please notice that the function named sec_to_time() did not get moved under the class block. It remains as an external function.
:1. [https://ict.senecacollege.ca/~raymonderic.chanbrauer/ops445/labs/lab7/lab7d.py Download] or create a new python file and name it as '''lab7d.py''' and place the code listed above in it.
:2. Save the file, and test the new time object in an interactive Python shell: <source lang="bash">
[rchan@centos7 lab7]$ python3
cd ~/ops445/lab7/
pwd #confirm that you are in the right directory
ls CheckLab7.py || wget https://ict.senecacollege.ca/~raymonderic.chanbrauer/ops435ops445/labs/LabCheckScripts/CheckLab7.py
python3 ./CheckLab7.py -f -v lab7d
</source>
cd ~/ops445/lab7/
pwd #confirm that you are in the right directory
ls CheckLab7.py || wget https://ict.senecacollege.ca/~raymonderic.chanbrauer/ops435ops445/labs/LabCheckScripts/CheckLab7.py
python3 ./CheckLab7.py -f -v lab7e
</source>
cd ~/ops445/lab7/
pwd #confirm that you are in the right directory
ls CheckLab7.py || wget https://ict.senecacollege.ca/~raymonderic.chanbrauer/ops435ops445/labs/LabCheckScripts/CheckLab7.py
python3 ./CheckLab7.py -f -v lab7f
</source>
: Try the following code. Have each in a separate Python file.
: '''[https://ict.senecacollege.ca/~raymonderic.chanbrauer/ops445/labs/lab7/lab7g.py lab7g.py]''' - local scope: <source lang="python">
#!/usr/bin/env python3
# Student ID: [seneca_id]
: Sometimes you want to have an object accessible from anywhere in your program, including inside and outside any functions. Here's an example:
:1. '''[https://ict.senecacollege.ca/~raymonderic.chanbrauer/ops445/labs/lab7/lab7h.py lab7h.py]''' - global scope <source lang="python">
#!/usr/bin/env python3
# Student ID: [seneca_id]
:3. Python has one weird quirk when it comes to global scope: if you assign something to an existing object inside a function - it will assume you want to create a new object in that function's local scope. That will hide the global object inside the function unless you declare it explicitly with the global keyword:
:4. '''[https://ict.senecacollege.ca/~raymonderic.chanbrauer/ops445/labs/lab7/lab7i.py lab7i.py]''' - global keyword <source lang="python">
#!/usr/bin/env python3
# Student ID: [seneca_id]
cd ~/ops445/lab7/
pwd #confirm that you are in the right directory
ls CheckLab7.py || wget https://ict.senecacollege.ca/~raymonderic.chanbrauer/ops435ops445/labs/LabCheckScripts/CheckLab7.py
python3 ./CheckLab7.py -f -v lab7i
</source>