1/48
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
The write() method immediately writes data to a file
False
file.write() method
writes a string argument to a file
a mode:
indicates how a file is opened
most used modes are:
'r' (read), 'w' (write)
mode 'a':
Open the file for appending
mode 'r'
Open the file for reading
mode 'w':
Open the file for writing.
The flush() file method can:
force the interpreter to flush the output buffer to disk
The statement f.write(10.0) always produces an error
True
The flush() method (and perhaps os.fsync()) forces the output buffer to write to disk
True
binary data
data stored as a sequence of bytes
bytes object
a sequence of single byte values
For a program run as "python scriptname data.txt", what is sys.argv[1]?
data.txt
A script "myscript.py" has two command line arguments, one for an input file and a second for an output file. Type a command to run the program with input file "infile.txt" and output file "out".
> python myscript.py infile.txt out
When using a with statement to open a file, the file is automatically closed when the statements in the block finish executing.
True
file.close() method
closes the file
file.write() method
writes a string argument to a file
the process of responding to unexpected or unwanted events and errors during execution
exception handling
EOFerror
input() hits an end-of-file condition (EOF) without reading any input
KeyError
A dictionary key is not found in the set of keys
ZeroDivisionError
Division by zero
ValueError
Invalid value
IndexError
Accessing an index that is out of range
Set:
unordered linear data type, every element is unique, using curly braces
set.intersection
Returns a new set containing only the elements in common between set and all provided sets.
set.union
Returns a new set containing all of the unique elements in all sets.
set.difference
Returns a set containing only the elements of set that are not found in any of the provided sets
len(set)
Find the length (number of elements) of the set.
set1.update(set2)
Adds the elements in set2 to set1.
set.add(value)
Adds value into the set.
set.remove(value)
Removes value from the set. Raises KeyError if value is not found.
set.pop()
Removes a random element from the set.
set.clear()
Clears all elements from the set.
A dictionary entry is accessed by placing a key in curly braces { }.
False
Dictionary entries are ordered by position.
True
dict[ ] =
adds elements to a dictionary or overwrites a value
When you open a file in write mode:
it automatically erases the file contents
When you write to a file that does not exist:
it creates that file
What are CSV files?
text based file that uses commas to separate data items
What is the purpose of exception handling?
To handle errors gracefully so the program does not crash.
Where do errors occur?
Inside the try block
If Python finds a error in the try block:
python quits running the code and moves the except block
What does the except block do?
It prints a message to the user stating an error has occurred
What are the two primary components to a class?
methods and attributes
What is the responsibility of the _init_ method?
initializes values to attributes
What is the self method?
referring the instance of class, calling the method
How do you access the attributes of a class?
Using a dot operator
What is better than accessing the attributes of a class?
using setters and getters
What is the difference between a tuple and list?
Tuples are immutable