1/25
Flashcards for COSC 131: Intro to Programming for Engineers, covering file processing, strings, and exceptions.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Text File
A collection of characters stored in a computer file system.
File Extension
Indicates the type of data the file likely contains and is used by the operating system to choose which application to open the file.
File Path
The location of a file within the directory structure of a computer's file system.
open(path, mode)
Opens a file for reading, writing, or appending.
read()
Returns the entire contents of a file as a single string.
write()
Writes data to a file.
close()
Closes a file, releasing system resources.
Escape Sequence
A character that represents a special control function, such as a newline or tab.
\n
Represents a new line.
\t
Represents a tab.
Multiline strings
Strings that contain embedded newline characters.
str.splitlines()
Splits a string into a list of substrings based on newline characters.
startswith()
Checks if a string starts with a specified substring.
endswith()
Checks if a string ends with a specified substring.
str.split()
Splits a string into a list of substrings based on a specified delimiter.
strip()
Removes leading and trailing whitespace from a string.
upper()
Changes the capitalization of a string to uppercase.
lower()
Changes the capitalization of a string to lowercase.
title()
Changes the capitalization of a string to title case.
urllib.request.urlopen()
Used to open Internet resources as files.
Exceptions
Unexpected events that disrupt the normal flow of a program's execution.
FileNotFoundError
An exception raised when a file cannot be found.
ValueError
An exception raised when a function receives an argument of an improper value.
try block
A block of code where exceptions are anticipated.
except block
A block of code that handles a raised exception.
raise
Force an exception to occur.