CS 320 midterm 1
virtual machine
"fake" machine running on physical machine allows us to run additional operating systems
function to split string into a list by spaces
.split()
Function to remove spaces at the beginning and end of a string
.strip()
When programming, how can you fix the issue that different OSs represent file paths differently? (\ for windows vs / for mac)
1. Tell anybody reproducing your results to use the same OS 2. Use the OS python backage to open file f=open(os.path.join("data", "file.txt"))
use cases of a version control system
1. Troubleshoot a bug 2. Tag "good" commits to create releases 3. Get/give feedback
Jobs of an operating system
1. allocation => assigns processing power (resources of CPU) for different processes 2. Abstraction => does "inconvenient" tasks (like interact with the hard drive)
how to use check_output to run a command with arguments
1. check_output("git --version", shell=TRUE) 2. (preferred) check_output(["git", "--version"])
steps to tag a commit
1. checkout the commit you want to tag/release 2. git tag <name of tag>
two ways to create a repository
1. copy it from a host like GitHub with git clone 2. make an empty one with git init
Is "in" faster on a list or a set?
A set
detached head state
HEAD is not pointing to a branch, it's pointing to a commit (even if it's the same commit as another branch)
Is HEAD a branch?
No. It shows where you are currently
what does the .git file contain?
Prior commits with other versions of the file
if all CPUs had the same instruction set, would we still need a Python interpreter?
Yes, you would still need it. You still need to convert high-level code into machine code
address space
a big "list" of bytes, per process, for all state
repository
a directory/folder on your computer that records a commit history
branch
a label attached to a commit that re-attaches to new commits
HEAD
a label for the current commit
tag
a long-term label associated with a commit
process
a running program
commit
a snapshot of files at a point in time - users manually run commands to preserve good versions
compiler
a tool for running the same code on different CPUs -- like an interpreter but happens before the program runs
what type of variable does check_output return?
byte object convert to string like this: str_output = str(output, encoding="utf-8")
CPU
chip that executes instructions, tracks position in code
conflict
differences that cannot automatically be merged
How to install a specific version of a dependency
ex: pip install pandas==0.25.1 - if you don't specify it will default to the latest stable version
What is a byte object?
example of a sequence - list, str, tuple are also sequences features: - indexing: seq[index] - slicing: seq[start index: exclusive end index] - iteration: for val in seq: - length: length(seq) - existence: <val> in seq
create a new branch without immediately checking out
git branch <branch name>
how to create and checkout a new branch
git checkout -b <name>
checkout an already existing branch
git checkout <branch name>
ghost commit
happens when you are in a detached head state and you make another commit; it will not update to a branch and will get lost in history - can be accessed with git checkout <commit number>
abstraction
hiding inconvenient details with something easier to use
address
index in the address space
byte
integer between 0 and 255
How does python fix the problem of different CPUs having different instruction sets? - program may not "fit" CPU
interpreters
git branch
list your branches. a * will appear next to the currently active branch
reproducibility
others can run our analysis code and get the same results
instruction set
pairing of CPU instructions/operatioins with numeric codes
encoding
pairing of characters with numeric codes
cloud
place where you can rent virtual machines and other services
check pandas version
print(pandas.__version__)
git restore <file>
restores file to last commit
ssh
secure shell -- tool that lets you remotely access another machine
how do you open documentation about a function inside jupyter?
shift+tab after entering the function name
operating system
software that allocates+abstracts resources
access the first argument in python
sys.argv[0] - will be the file name (different than C!) for example, it would be fileName.py for "python3 fileName.py"
allocation
the giving of a resource to a process
what does time.time() return?
the number of seconds elapsed since January 1st, 1970
resource
time on CPU, space in memory, space on SSD, etc.
merge
to combine changes on another branch into the current branch
interpreters (like python.exe)
translates human code to machine code for your CPU - makes it easier to run the same code on different machines
git diff
what changes have been made to repository (before commit)
how can you run a command in python and see the output?
with check_output from subprocess ex: from subprocess import check_output output = check_output("pwd")