Posts

Showing posts from June, 2020

Working with Python -- File Handling

Image
Introduction File Handling is a very important portion for any application. In Python, we have several function to Create, Read, Update and Delete file. In this blog post, we are trying to discuss about Python File handling. Hope it will be interesting. Open Function This is the key function to working with file. The Open function takes two parameters. One is File name and second is mode. "r"   -  Read   - Default value. Opens a file for reading, error if the file does not exist "a"  -  Append  - Opens a file for appending, creates the file if it does not exist "w"  -  Write  - Opens a file for writing, creates the file if it does not exist "x"  -  Create  - Creates the specified file, returns an error if the file exists In addition of that, we can specify that the file can be treated as Binary or as Text file. "t"  -  Text  - Default value. Text mode "b"  -  Binary  - Binary mode (e.g. images) Example: f =  open ( "demof

Working with Python – JSON

Image
Introduction JSON (Java Script Object Notation) is very popular nowadays for transmitting data. Here in this Blog Post we are going discuss about it. Hope it will be interesting.   Importing JSON module Before working with JSON, we have to import the JSON module in Python. import json Parsing JSON in Python We can Parse JSON in multiple ways in Python mentioned bellow. Parsing JSON to Dictionary We can Parse a JSON using json.loads() methods, which returns a Dictionary.   Example: Import   json person = '{"name": "Mayuree", "languages": ["English", "Bengali"]}' person_dict = json.loads(person) print( person_dict) print(person_dict['languages']) Output: {'name': 'Mayuree', 'languages': ['English', 'Bengali']} ['English', 'Bengali'] Here, person is a JSON string and person_dic is adictionary.     Read the JSON File   No

Working with Python – Class and Object Concept

Image
Introduction Python is an Object oriented Language. An object contains Propertied and Method and the Class is the blueprint of creating Object. In this Blog post, we are going to discuss about Class and Objects of Python. How to Create a Class To create a class we must use the keyword  Class . Example: class  ExampleClass:       x =  5 In this example we are just create a class named ExampleClass .   How to Create an Object After creating class, we have to create the Object. class  ExampleClass:       x =  5 a = ExampleClass() print (a.x)   In the above example, the class is as a simplest form. To understand the class, we have to understand the  __Init__()   function     Understanding the __init__() Function Hope, we all have the knowledge of  constructor  in C++ Language. __init__() function do the same thing as Constructer does. This function is called automatically when the Object is created. Let us take a simple example to understand that. Exa