Rajendra Dharmkar has Published 452 Articles

How to pass Checkbox Data to Python CGI script?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 16-Jun-2020 12:17:52

374 Views

Passing Checkbox Data to CGI ProgramCheckboxes are used when more than one option is required to be selected.Here is example HTML code for a form with two checkboxes − Maths Physics The result of this code is the following form −Maths  Physics Select SubjectBelow is checkbox.cgi script ... Read More

How to pass Radio Button Data to Python CGI script?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 16-Jun-2020 12:16:41

799 Views

Passing Radio Button Data to CGI ProgramRadio Buttons are used when only one option is required to be selected.Here is example HTML code for a form with two radio buttons − Maths Physics The result of this code is the following form − Maths  Physics Select SubjectBelow is ... Read More

What Python regular expression can be used in place of string.replace?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 16-Jun-2020 12:08:42

67 Views

The following code replaces all the characters from given string with ''Exampleimport re line = 'this is a text with in between and then there are instances ... where the number ranges from 0-99.\ and there are many other lines in the text files \ with such tags ' line ... Read More

How does B regular expression work in Python?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 16-Jun-2020 11:54:00

463 Views

The word boundary \b matches positions where one side is a word character (usually a letter, digit or underscore)\B matches all positions where \b doesn't match.The following code shows how regexpr \B worksimport re result = re.findall(r'\Bcat', 'certificate') result2 = re.findall(r'\Bcat', 'tomcat') result3 = re.findall(r'\Bcat', 'catfish') print result, result2, result3This ... Read More

How you can get a true/false from a Python regular expressions?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 16-Jun-2020 11:43:03

3K+ Views

When you use match and search methods of module re, if there is a match, it has bool value of True and if there is no match, you get None that has a bool value of False.Match objects are always true, and None is returned if there is no match>>> ... Read More

How to encode custom python objects as BSON with Pymongo?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 16-Jun-2020 11:29:35

283 Views

To encode custom python objects as BSON with Pymongo, you have to write a SONManipulator. From the docs:SONManipulator instances allow you to specify transformations to be applied automatically by PyMongo.from pymongo.son_manipulator import SONManipulator class Transform(SONManipulator):   def transform_incoming(self, son, collection):     for (key, value) in son.items():       ... Read More

How does class variables function in multi-inheritance Python classes?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 16-Jun-2020 09:04:20

337 Views

A class can be derived from more than one base classes in Python. This is called multiple inheritance.In multiple inheritance, the features of all the base classes are inherited into the derived class. The syntax for multiple inheritance is similar to single inheritance.class Super1:     pass class Super2:   ... Read More

How I can create Python class from JSON object?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 16-Jun-2020 08:38:28

907 Views

We can use python-jsonschema-objects which is built on top of jsonschema.The python-jsonschema-objects provide an automatic class-based binding to JSON schemas for use in Python.We have a sample json schema as followsschema = '''{     "title": "Example Schema",     "type": "object",     "properties": {         ... Read More

How to serialize a Python class?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 16-Jun-2020 08:35:42

259 Views

Object serialization and deserialization are a routine aspect of any non-trivial Python program. Saving to a file, reading a configuration file, responding to an HTTP request, all involve object serialization and deserialization. Serialization and deserialization involve various schemes, formats and protocols to stream Python objects and to get them back later ... Read More

How we can instantiate different python classes dynamically?

Rajendra Dharmkar

Rajendra Dharmkar

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

751 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 ... Read More

Advertisements