Found 27104 Articles for Server Side Programming

How we can convert Python objects into JSON objects?

Niharika Aitam
Updated on 15-May-2023 13:53:04

762 Views

JSON can be abbreviated as JavaScript Object Notation. Json means a script of a text file in a programming language to transfer and store the data. Json supported by the python programming language using a built-in package named json. The Json text is given in the quoted string format which contains in the key and value within the curly braces{}. This looks like a dictionary format in python programming language. For using the json package in the python programming language we have to import the json package in python script. In the Json package we have ... Read More

How to find out if a Python object is a string?

Niharika Aitam
Updated on 15-May-2023 13:49:07

224 Views

We know that Python is an object oriented programming language. By using the oops concept we can make the code and functions work together in a better way. The OOPs in python help us to deal with the real time entities with inheritance, polymorphism, encapsulation etc. Group of objects is called a class. The class contains the blueprint, which takes as the reference to create the object. This contains attributes and methods in a logical entity. Let’s understand the usage of the class in object oriented programming language by a real time scenario. Consider a library. ... Read More

How to attach a C method to existing Python class?

Niharika Aitam
Updated on 15-May-2023 13:48:03

142 Views

We are currently coding of python C methods are being used. The base of all the libraries such as Numpy, Opencv, pytorch etc are built with the C and C++ i.e. these libraries internally call the Compiled C code where code will be executed in the machine and the result will be return in python wrapper. Why are we using the C methods in python? The reason why we are using the C method in python is the performance. The python performance will be decreased because of the dynamic typing. It has to reduce the type of operands to ... Read More

Do you think declarations within Python class are equivalent to those within __init__ method?

Rajendra Dharmkar
Updated on 16-Jun-2020 08:19:01

73 Views

Declarations anywhere in the class(other than in __init__) and declarations in the __init__method are not the same. The following code shows this to be true.Exampleimport sys class foo():     print 'within class'     def __init__(self):         print 'within init'     def do_smthng(self):         print 'do something' def main():     f=foo()     f.do_smthng()     return 0 if __name__ == '__main__':     sys.exit( main() )Outputwithin class within init do something

What's the best place for python classes in a Django project?

Niharika Aitam
Updated on 15-May-2023 13:46:30

201 Views

Django is one of the frameworks used along with python to create the web pages in an efficient manner. It is also called as the framework included with batteries why because by default the Django framework gives the admin interface and database interface like SQLite 3 etc. It also provides us the default readymade components namely user authentication handling like sign in, signup and sign out. It provides the management panel for our website, forms, uploading the files etc. Why are we using the Django framework? Django is known for its scalability and comprehensive documentation. This framework is used by ... Read More

How we can split Python class into multiple files?

Niharika Aitam
Updated on 15-May-2023 13:44:38

2K+ Views

OOPs is abbreviated as object oriented programming language. It helps us to deal with the real time entities with inheritance, polymorphism, encapsulation etc. By using the oops concept we can make the code and functions work together in a better way. Group of objects is called a class. The class contains the blueprint, which takes as the reference to create the object. This contains attributes and methods in a logical entity. Now let’s see why we have to split the code into multiple classes. If we create the entire code in the single class, it will be easy to write ... Read More

How to organize Python classes in modules and/or packages

Niharika Aitam
Updated on 15-May-2023 13:42:15

751 Views

There are different modules or packages in the python classes. When we use their names as it is in the code it will be somewhat clumsy and not good to see. So, we need to organize the python classes in modules and packages. Modules are the group of functions, classes or any block of code kept in a single file. The file extension of the methods will be .py. If the python code is with 300-400 lines of code, then it can be made as a module for better understandability. The module name can be available as ... Read More

What are Getters/Setters methods for Python Class?

Niharika Aitam
Updated on 15-May-2023 13:30:49

550 Views

In python we have different methods available to make our work very easy and simple. Among the methods available in python we have two methods namely getter and setter. These methods play a vital role in the object oriented programming language of python to hide the private variables. These methods of python are not as same as the getters/setters methods in other object oriented programming languages. These are used in object oriented programming language for data encapsulation. These are used with the below conditions The getters/setters in python are used to validate the logic for getting and ... Read More

How we can instantiate different python classes dynamically?

Rajendra Dharmkar
Updated on 16-Jun-2020 08:29:21

744 Views

To instantiate the python class, we need to get the class name first. This is achieved by following codedef get_class( kls ):     parts = kls.split('.')     module = ".".join(parts[:-1])     m = __import__( module )     for comp in parts[1:]:         m = getattr(m, comp)                     return mm is the classWe can instantiate this class as followsa = m() b = m(arg1, arg2) # passing args to the constructor

Explain Inheritance vs Instantiation for Python classes.

Rajendra Dharmkar
Updated on 09-Sep-2023 23:14:33

10K+ Views

InheritanceBeing an Object Oriented language, Python supports inheritance, it even supports multiple inheritance. Classes can inherit from other classes. A class can inherit attributes and behaviour methods from another class, called the superclass. A class which inherits from a superclass is called a subclass, also called heir class or child class. In other words inheritance refers to defining a new class with little or no modification to an existing class.class A:        # define your class A pass class B:         # define your class B pass class C(A, B):   # subclass of A ... Read More

Advertisements