Found 26504 Articles for Server Side Programming

Namespaces and Scope in Python

gireesha Devara
Updated on 01-Sep-2025 11:46:57

2K+ Views

In Python we work with variables, functions, libraries and modules, etc. Sometimes, the variable name you choose may already exist as the name of another variable, function, or method. This can be confusing or it might lead to unexpected behavior in your program. In such scenario, we need to learn about how all these names are managed in Python. This is the concept of namespaces and scoping. Namespaces in Python A namespace is a mapping from names to objects, which means stores the names you define in your program (such as, variable names, function names, class names, etc.) and maps ... Read More

Encode and decode XDR data using Python xdrlib

Pradeep Elance
Updated on 28-Dec-2020 11:04:10

610 Views

Encoders and decoders for the External Data Representation (XDR). When we transport data between different external sources, this is the commonly used format that is used. It useful for creation and transfer of complex data structures. XDR provides a service associated with the OSI Presentation Layer.In the below program we see how the data is getting packed and unpacked using the xdrlib module.Exampleimport xdrlib p = xdrlib.Packer() print(type(p)) lst = [1, 2, 3] p.pack_list(lst, p.pack_int) print(p) u = xdrlib.Unpacker(p) print(type(u)) print(lst)Running the above code gives us the following result −Output [1, 2, 3]Read More

Encode and decode uuencode files using Python

Pradeep Elance
Updated on 28-Dec-2020 10:57:25

1K+ Views

It is a common requirement during file transfers to encode and decode them for various reasons like encryption, compression or just because they are going to be processed by different OS or file reading programs. The uuencode module helps us on both encoding and decoding files as shown below.Encode the fileWe will use the below image for encoding and later decoding it to get it back.In the below program we use the encode function to encode the given image and read the content of the file after encoding.Exampleimport uu infile = "E:\tp_logo.JPG" uu.encode(infile, 'encoded_logo.JPG') f = open("E:\TP\encoded_logo.JPG", 'r') ... Read More

Encode and decode MIME quoted-printable data using Python

Pradeep Elance
Updated on 28-Dec-2020 10:55:16

2K+ Views

Many times we need to deal with data which not always has the regular ASCII characters. For example, an email in a different language other than English. Python has mechanism to deal with such characters by using MIME (Multipurpose Internet Mail Extensions) based module. In this article we will see how we can decode such characters in an email or otherwise in some straight inputs.Using email packageThe email package has modules namely mime and charset which can carry out the encoding and decoding work as shown in the below example. We have taken an email message containing Unicode characters and ... Read More

Python - Button Action in Kivy

Pradeep Elance
Updated on 28-Dec-2020 10:53:23

606 Views

Kivy is an open source Python library for rapid development of applications that make use of innovative user interfaces, such as multi-touch apps. It is used to develop the Android application, as well as Desktops applications. In this article we will see how to use events when a button is pressed.In the below example we have created a button and a label in a horizontal BoxLayout. We give initial text to the button and label. Then we create an event for clicking the button which changes the text both in the button and in the label. It is a single ... Read More

Python - BoxLayout widget in Kivy

Pradeep Elance
Updated on 28-Dec-2020 10:51:13

723 Views

Kivy is an open source Python library for rapid development of applications that make use of innovative user interfaces, such as multi-touch apps. It is used to develop the Android application, as well as Desktops applications. In this article we will see how to use the BoxLayout widget to create buttons of different orientation and colours.In the below code we first create an outer box whose orientation is vertical. Then we create a row 1 with horizontal orientation. Then two other rows again with vertical orientation. We wrap all these rows in the outer box and giver different text and ... Read More

Python - AnchorLayout in Kivy

Pradeep Elance
Updated on 28-Dec-2020 10:47:44

656 Views

Kivy is an open source Python library for rapid development of applications that make use of innovative user interfaces, such as multi-touch apps. It is used to develop the Android application, as well as Desktops applications. In this article we will see how to use the anchor layout positioning.Using AnchorLayouts we place the widgets at one of the borders. The class kivy.uix.anchorlayout.AnchorLayout implements the anchor layout. Both the anchor_x parameter and anchor_y parameter can be passed the values ‘left’, ‘right’ and ‘center’. In the below program we create two buttons, attach them to two anchors and keep them in a ... Read More

Python - Convert list of nested dictionary into Pandas Dataframe

Pradeep Elance
Updated on 28-Dec-2020 10:39:57

5K+ Views

Many times python will receive data from various sources which can be in different formats like csv, JSON etc which can be converted to python list or dictionaries etc. But to apply the calculations or analysis using packages like pandas, we need to convert this data into a dataframes. In this article we will see how we can convert a given python list whose elements are a nested dictionary, into a pandas Datframe.We first take the list of nested dictionary and extract the rows of data from it. Then we create another for loop to append the rows into the ... Read More

Program to Find Out the Smallest Substring Containing a Specific String in Python

Arnab Chakraborty
Updated on 26-Dec-2020 11:57:01

1K+ Views

Suppose we have two strings s and t. We have to find the smallest substring in s, where t is also a subsequence of the substring. If that type of substring does not exist, we will return a blank string, and if there are multiple smallest substrings, we will take the leftmost one.So, if the input is like s = "abcbfbghfb", t = "fg", then the output will be fbgTo solve this, we will follow these steps −N := size of Sdp := a new list of size N initialized with infinityfor i in range 0 to N − 1, ... Read More

Program to Find Out Median of an Integer Array in C++

Arnab Chakraborty
Updated on 26-Dec-2020 11:55:00

307 Views

Suppose we have to implement a class named MedianClass which contains the following methods −add(value) which adds a value to the data structure.median() finds the median of all the numbers currently present in the data structure.So, if we add 5, 3, 8 and find median, the output will be 5.0, then if we add 9 and find the median, the output will be 6.5.To solve this, we will follow these steps −Define priority queue left and rightDefine addNum method, this will take the number as input −if left is empty or num < top element of left, then, insert num ... Read More

Advertisements