Showing posts with the label self object

Featured Post

Python Program: JSON to CSV Conversion

JavaScript object notion is also called JSON file, it's data you can write to a CSV file. Here's a sample python logic for your ready reference.  You can write a simple python program by importing the JSON, and CSV packages. This is your first step. It is helpful to use all the JSON methods in your python logic. That means the required package is JSON. So far, so good. In the next step, I'll show you how to write a Python program. You'll also find each term explained. What is JSON File JSON is key value pair file. The popular use of JSON file is to transmit data between heterogeneous applications. Python supports JSON file. What is CSV File The CSV is comma separated file. It is popularly used to send and receive data. How to Write JSON file data to a CSV file Here the JSON data that has written to CSV file. It's simple method and you can use for CSV file conversion use. import csv, json json_string = '[{"value1": 1, "value2": 2,"value3

Python Default Argument is Self Why do We Need it

Python self as default argument, here is the reason. Below, you will find an example and the importance of self-argument. Structure of a class The default argument is self. The self-argument states the function belongs to the class that we refer to here. Access to class members' details of one member to another is possible through self-argument. So self-argument is mandatory. class <name of the class>: def <function name>(<arguments>): ... <members> Self Argument A python class consists of methods these also called functions. The default self-argument you need to supply in all the class methods . Python class with self argument class employee:      def getdata(self): 'Enter name\t:')           self.age=input('Enter age\t:')     def putdata(self):           print('Name\t:',          print('Age\t:',self.age)  e1=employee()  e1.getdata()  e1.putdata() Output from python class Here,  I have I