Rajendra Dharmkar has Published 784 Answers

How do you compare Python objects with .NET objects?

Rajendra Dharmkar
Published on 24-Jan-2018 11:38:56
By default, all .NET objects are reference types and their equality and hash code is determined by their memory address. Additionally, assigning a variable to an existing object just makes it point to that address in memory, so there is no costly copying occurring. It appears that this is true ... Read More

How to access Python objects within objects in Python?

Rajendra Dharmkar
Published on 24-Jan-2018 11:06:53
The objects within objects can be accessed as followsExampleclass P:  def __init__(self):    self.w = Q() class Q:  def __init__(self):   self.list = [3,4,5]  def function(self):   self.list[2] = 7 y = P() f = [y] print f[0].w.function() print f[0].w.listOutputGives output asNone [3, 4, 7]

What are Python OOP Basics?

Rajendra Dharmkar
Published on 24-Jan-2018 08:48:42
OOP concepts in PythonPython is an object-oriented programming language. We can easily create and use classes and objects in Python.Major object-oriented concepts of Python programming language are given below:Object ; Class;  Method;  Inheritance; Polymorphism ; Data Abstraction ; EncapsulationObjectObject is an entity that has state and behaviour. It may be ... Read More

How to convert JSON data into a Python object?

Rajendra Dharmkar
Published on 24-Jan-2018 08:34:43
The following code converts a json object(string) into a python object(dictionary). We import the json module and use the json.loads() method to do this.Exampleimport json json_string = '{"name":"Sonali", "age": 21, "designation":" Software developer"}' print type (json_string) def func(strng):     a =json.loads(strng)     print type(a)     print a ... Read More

How we can convert Python objects into JSON objects?

Rajendra Dharmkar
Published on 24-Jan-2018 08:03:46
Suppose we have a list object a = [1,2,3]. We convert a python object into a JSON object by importing json module and using the method json.dumps() as follows.>>> a = [1,2,3] >>> import json >>> json.dumps(a) '[1, 2, 3]'The JSON object we got is '[1, 2, 3]'

Is there any Python object inspector?

Rajendra Dharmkar
Published on 24-Jan-2018 07:45:02
There is no single built-in or normal function that acts as a object inspector in Python. There are functions like type(), dir(), vars() or modules like inspect which can be used to find the attributes, properties and methods of any object under inspection.There other functions like id(), getattr(), hasattr(), globals(), ... Read More

How to return an object from a function in Python?

Rajendra Dharmkar
Published on 24-Jan-2018 07:33:14
The return statement makes a python function to exit and hand back a value to its caller. The objective of functions in general is to take in inputs and return something. A return statement, once executed, immediately halts execution of a function, even if it is not the last statement ... Read More

How to insert a Python object in Mongodb?

Rajendra Dharmkar
Published on 24-Jan-2018 06:49:19
You can use the pymongo library in Python to connect to a MongoDB database and use it to insert, update, delete, etc objects in Python. The library supports Python datetime objects out of the box and you dont need to do anything special to insert dates in Mongo using PyMongo. ... Read More

How to insert a Python object in MySQL?

Rajendra Dharmkar
Published on 24-Jan-2018 06:39:15
Assuming that a MySQL database named 'test' is present on the server and a table named employee is also created. Let the table have five fields fname, lname, age, gender, and salary.Suppose we want to insert a tuple object containing data of a record defined as follows into the Msql ... Read More

How to know if an object has an attribute in Python?

Rajendra Dharmkar
Published on 24-Jan-2018 06:22:00
We can use hasattr() function to find if a python object obj has a certain attribute or property. hasattr(obj, 'attribute'):The convention in python is that, if the property is likely to be there, simply call it and catch it with a try/except block. If the property is likely to not be ... Read More
Previous 1 ... 3 4 5 6 7 8 9 ... 79 Next
Advertisements