Category: Python

__name__ Variable in Python

__name__ Variable in Python Most of the programming languages use the main method or function as the starting point of execution in any program. But what about Python? Generally, the execution of a python program(script) starts from the very first line that is at the indentation level 0 of that program. However, when a python program is executed, before its […]

Python File Handling Operations

Python File Handling Operations In this tutorial, we will learn how to read content from a file, then write text to any file and how to copy a file content to another file. We will also use tell and seek methods for file handling. Python – Reading a File Let’s start by learning how to read a file. readline() function […]

File Handling in Python

File Handling in Python Not in every case data is supposed to be taken directly from the user. There may arise cases when you have to take data from a stored raw file, in such cases, you will have to connect those files with a program such that it can read, write or modify the […]

Python Exception Handling: raise Keyword

Python Exception Handling: raise Keyword While the try and except block are for handling exceptions, the raise keyword on the contrary is to raise an exception. Following is the syntax: raise EXCEPTION_CLASS_NAME Taking a simple usage example: raise ZeroDivisionError Traceback (most recent call last): File “”, line 1, in <module> raise ZeroDivisionError ZeroDivisionError: division by zero If you have a piece of code where along […]

Python Exception Handling: finally

Python Exception Handling: finally The finally code block is also a part of exception handling. When we handle exception using the try and except block, we can include a finally block at the end. The finally block is always executed, so it is generally used for doing the concluding tasks like closing file resources or closing database connection or may be ending the program execution with a […]

Back To Top