Anna GE 3151 - UNIT V: FILES, MODULES, PACKAGES

Unformatted text preview:

UNIT V FILES MODULES PACKAGES Files and Exception Handling 1 Text Files Opening a file file open file txt r r read w write a append Reading from a file content file read Writing to a file file write Hello World Closing a file file close 2 Reading and Writing Files Using the with statement to automatically close the file after use Iterating over lines in a file 3 Format Operator Used for string formatting and interpolation Command Line Arguments Python scripts can accept command line arguments when executed from the terminal or command prompt Errors and Exceptions Errors are issues that prevent your program from running while exceptions are raised when something goes wrong during runtime 1 Handling Exceptions Using try except blocks to catch and handle exceptions Raising custom exceptions with the raise statement Modules and Packages Modules are Python files containing reusable code while packages are collections of modules 1 Importing Modules import module name from module name import function name 2 Creating and Using Packages Organizing modules into directories Using the init py file to mark a directory as a package Illustrative Programs 1 Word Count 2 Copy File 3 Voter s Age Validation 4 Marks Range Validation 0 100


View Full Document

Anna GE 3151 - UNIT V: FILES, MODULES, PACKAGES

Download UNIT V: FILES, MODULES, PACKAGES
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view UNIT V: FILES, MODULES, PACKAGES and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view UNIT V: FILES, MODULES, PACKAGES 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?