Q.
1) WAP to understand the order of execution of methods in
several base classes according to MRO
Code:
class A:
def rk(self):
print(" In class A")
class B(A):
def rk(self):
print(" In class B")
class C(A):
def rk(self):
print("In class C")
# classes ordering
class D(B, C):
pass
r = D()
[Link]()
Output :
MRO:
Q.2) WAP to pickle and unpickle EMP Class Object.
Ans:
import pickle
class employee:
def __init__(self,id=0,name="a",salary=0):
self.dic1={}
self.dic1["id"]= id
self.dic1["Name"]= name
self.dic1["Salary"]= salary
outfile = open("[Link]","wb")
[Link](self.dic1,outfile)
[Link]()
def display(self):
infile=open("[Link]","rb")
dic2=[Link](infile)
[Link]()
print("ID:{}\nName:{}\nSalary:{}".format(dic2["id"],dic2["Name"],dic2["Salary"]))
n=input("Enter ID,name and salary").split()
ob=employee(int(n[0]),n[1],n[2])
Q.3) WAP to create and use deque.
Ans:
import collections
DoubleEnded = [Link](["Mon","Tue","Wed"])
print (DoubleEnded)
print("Adding to the right: ")
[Link]("Thu")
print (DoubleEnded)
print("Adding to the left: ")
[Link]("Sun")
print (DoubleEnded)
print("Removing from the right: ")
[Link]()
print (DoubleEnded)
print("Removing from the left: ")
[Link]()
print (DoubleEnded)
print("Reversing the deque: ")
[Link]()
print (DoubleEnded)
Output:
[Link] to implement chat between Server and client
Server:
import socket
def server_program():
host = [Link]()
port = 5000
server_socket = [Link]()
server_socket.bind((host, port))
server_socket.listen(2)
conn, address = server_socket.accept()
print("Connection from: " + str(address))
while (True):
data = [Link](1024).decode()
if not data:
break
print("from connected user(bot): " + str(data))
data = input('qwerty-> ')
[Link]([Link]())
[Link]()
if __name__ == '__main__':
server_program()
Client:
import socket
def client_program():
host = [Link]()
port = 5000
client_socket = [Link]()
client_socket.connect((host, port))
message = input("bot-> ")
while [Link]().strip() != 'bye':
client_socket.send([Link]())
data = client_socket.recv(1024).decode()
print('Received from server(Sanket): ' + data)
message = input("bot-> ")
client_socket.close()
if __name__ == '__main__':
client_program()
Output:
Client
Server :
[Link] between Pearl and Python
FEATURE PERL PYTHON
Python is a widely used general-
Perl is a general purpose high
purpose, high level programming
level language popular for CGI
language. Due to its rich library and
scripts. Some of the popular
Introduction support, it has wide applications in
projects in Perl are CPanel and
Web Development, Machine
Bugzilla. It was initially designed
Learning, Desktop Applications,
to replace complex shell scripts.
etc.
Python deals with whitespaces and
Perl does not care about a syntax error generates if
Whitespaces
whitespaces. whitespaces are not according to
Python.
Python accentuates support for
Perl accentuates support for
common methodologies such as
Focus common tasks such as report
object-oriented programming and
generation and file scanning.
data structure design.
The .pl file extension is used to The .py file extension is used to
File Extension save Perl Scripts. For example save Python Scripts. Example:
[Link] [Link]
It is not necessary to end the
End of All statements should end with statements with a semi colon in
Statement a semi colon in Perl. Python as it deals with
whitespaces.
For Inline comments, we use #
in Perl. Python also uses # for Inline
comments.
e.g. #Inline-Comment in Perl
e.g. #Inline-Comment in Python
whereas for documentation we
Comments and use but for documentation we use
Documentation
= and =cut “”” i.e. Three inverted commas
e.g. =Documentation in Perl e.g. “””Documentation in Python
starts from here and ends here. starts from here and ends here.”””
=cut
Statement Perl uses braces to mark the Python use indentations to mark
Blocks statement blocks. the statement blocks.
Some data types contained by Some data types contained by
Datatypes Perl are numeric, string, Scalars, Python are numeric, strings, lists,
Arrays, Hashes. dictionaries, tuples.