exam 3 lec notes Flashcards
assert statements enable you to convert _____ errors into _______ errors
semantic, runtime
what is the syntax for assert ?
assert BOOLEAN_EXPRESSION
what happens when assert evaluates to true? what about false?
true: nothing happens, moves on
false: assertion error
what type of errors are called ‘exceptions’?
runtime errors
what is ‘catching’ an expression in terms of try and except blocks?
where there is an exception, the try block gets terminated and the except block runs instead
what is ‘e’ in exception?
the object instance, you add it after exception if you want a general overview (?) or your error
what does str(e)?
gives you the reason for the exception
whats does type(e) do?
gives you the type of error
what does raising and error do in python?
explicitly signals something is wrong and explains the error
what does .read() convert the contents in a file to?
a long str
what needs to be explicitly written for writing in a file?
\n
what does os.listdir do?
list all the paths and directories in a directory
what does os.mkdir do?
creates a new directory
what does os.path.isfile do?
returns true if a path points to a file, otherwise returns false
what does os.path.isdir do?
returns true if path points to directory, otherwise it returns false
what does os.path.join do?
joins one or more path components into a single path
what is a pandas series?
a combination of dict and list
what can pandas series be made from?
list or dict
if the ‘exception’ is too broad in a try and except block? what could you do to try and catch a specific error?
you can specify the type of error you want to catch by writing the type after the exception
what is the difference between ‘+’ and ‘append()’ method on lists?
+ operator creates a brand new object instance
append() modifies the existing list object instance
what is a path on python?
a string that represents the location of a file or directory on a computer’s file system
what do you pass as an argument to open(…)?
the relative path, you should not hardcode the ‘/’ or ‘'
what does the read() function return?
the file contents as one big string
what does calling list() on a file do?
converts file contents as a list