Exception Handling in Python (Part II)

exception (itvoyagers.in)

Exception Handling in Python (Part II) Raising an Exception Raise keyword to raise built-in exceptions We can handle runtime exceptions in Python but we can also raise it deliberately using raise keyword. In Exception handling, raise clause is used to raise an exception. We can also pass a message or a value to an exception … Read more

Exception Handling in Python (Part I)

Exception Handling (itvoyagers.in)

Exception Handling Exception handling is a mechanism used to handle the abnormal situation (Exception) raised, which interrupts the normal flow of program. Exception handling in python is similar to java but in java catch clause is used where as in python catch clause is replaced with except clause. try….except…else In this try block will be … Read more

Exceptions in Python

exception (itvoyagers.in)

Exceptions in Python What is exception? An event which may occur during execution of program ,that interrupts normal flow of program is called an exception.Exception is an abnormal condition in program code.When error occurs ,Python generates exceptions which can be handled and avoids program from getting crash. How to handle exceptions? Whenever an event occurs … Read more

Iterator and Iterables in Python

iterator (itvoyagers.in)

Iterator and Iterables in Python We can use iterators and iterable using for loop,genators etc.Iterators are objects used to travesrse using loop.We can build our own iterators using __iter__ and __next__.Topics to cover in this post: What are iterators and iterables in Python? Iterating using iterator in python & user defined Iterators Iterators in for … Read more

Directory in Python and its methods

directory (itvoyagers.in)

Directory in Python and its methods Directories Directories are holding all python files and directories.To manipulate this directories OS Module needs to be imported.This module consists of many methods to handle directories. List of some directory functions: getcwd() mkdir() chdir() rmdir() listdir() rename() getcwd(): This method is used to show Current Working Directory. To use … Read more

Remaining file methods in Python

file methods (itvoyagers.in)

File methods Summarizing file methods: open() close() read() write() rename() remove() Among the above methods we have already explained open() ,read(),write() and close() in previous posts. Now we will explain remove and rename methods of file object. rename(): This method is used for renaming existing file.To use this method it is important to import os … Read more

How to read, write and append in a file using Python?

read (itvoyagers.in)

Read, Write and Append in a file using Python Reading & Writing in files The user must open a file first using open() to read it.The reading of string always starts with beginning of the file. Methods to perform read operation read() ,readline() & readlines() read() : This method is used to read entire size … Read more