Posts

Showing posts from August, 2015

python: readline() and read()

[root@mysql Scripts]# ./file1.py If we give print han1 Then output would be File is open only once Actual output should be like this so use han1.readline() [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] If you use han1.readline(10) Then it will print next 10 characters as in upper line already pritn upto first   I am a bes If you use again han1.readline(10) then it will print next 10 character untill didnt get next line t player If you use han1.readline(15) then again print next 15 characters  I am the best p ------------------now start read()-------------------- Now use han1.read() layer I am  best player I am an best player I am a best player I am a best player I am a best player I am a best player I am a best player I am a best player This will print only Blank lines han1.read(20)....  because file completly open by last command now nothing to read in file so only blank spaces...:)

Python: Open file example 1

#!/usr/bin/python han1 = open("davinder.txt","r") print "\n\n" print "If we give print han1 Then output would be", han1, "\n\n" print "File is open only once" print "Actual output should be like this so use han1.readline()", han1.readline(),"\n" print "If you use han1.readline(10) Then it will print next 10 characters as in upper line already pritn upto first \n ", han1.readline(10) print "If you use again han1.readline(10) then it will print next 10 character untill didnt get next line", han1.readline(10) print "If you use han1.readline(15) then again print next 15 characters ", han1.readline(15) print "------------------now start read()--------------------" print "Now use han1.read()", han1.read() Output: [root@mysql Scripts]# ./file1.py If we give print han1 Then output would be File is open only once Actual output should be like this so use han1.read...

Python: Simple for loop

#!/usr/bin/python import sys c = "I am a best player" a = range(1,11) print a for b in a:         print  c OUTPUT: [root@mysql Scripts]# python For.py [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] I am a best player I am a best player I am a best player I am a best player I am a best player I am a best player I am a best player I am a best player I am a best player I am a best player  

python: Print the table of enter value

#!/usr/bin/python import sys c = input("What Table you want to learn ") print "you have entered table of ",c a = range(1,11) print a for b in a:         print  c,"*",b,"=", b * c Output:  [root@mysql Scripts]# python for.py What Table you want to learn 4 you have entered table of  4 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] 4 * 1 = 4 4 * 2 = 8 4 * 3 = 12 4 * 4 = 16 4 * 5 = 20 4 * 6 = 24 4 * 7 = 28 4 * 8 = 32 4 * 9 = 36 4 * 10 = 40 [root@mysql Scripts]# python for.py What Table you want to learn 6 you have entered table of  6 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] 6 * 1 = 6 6 * 2 = 12 6 * 3 = 18 6 * 4 = 24 6 * 5 = 30 6 * 6 = 36 6 * 7 = 42 6 * 8 = 48 6 * 9 = 54 6 * 10 = 60

IF and elif and else

#!/usr/bin/python import sys # By default argument will count script name also so I have reduced -1 for exact value arg_count = len(sys.argv) - 1 #print what I have entered in arguments" print "\nYou have entered ",arg_count, "arguments", sys.argv[1],",", sys.argv[2] # Store Argurments in variable Arg_first = sys.argv[1] print "\nType of first argument is ", type(Arg_first) # store second arg in variable Arg_Sec  =  sys.argv[2] print "\nType of second argument is", type(Arg_Sec) #By default argement will be in string type so converting in integer for mathematical a = int(Arg_first) print "\nAfter converting argument type is", type(a) b = int(Arg_Sec) print "After converting second argument type is", type(b) if a == b:         print "\nAddition of Argument 1 and Argument 2 is", a + b elif a < b:         print "\nMultiple of Arg1 and Arg2 is", a * b elif a > b:       ...

Argument Printing

#!/usr/bin/python import sys print len(sys.argv) print sys.argv print sys.argv[1] name = sys.argv[1] age =  sys.argv[2] print "My name is ",name, "and age is",age Output: [root@mysql Scripts]# python if.py davinder 35 3 ['if.py', 'davinder', '35'] davinder My name is  davinder and age is 35

arguments Printing

#!/usr/bin/python import sys print len(sys.argv) print sys.argv print sys.argv[1] Output: [root@mysql Scripts]# python if.py 3 3 3 ['if.py', '3', '3'] 3 [root@mysql Scripts]# python if.py 5 3 3 ['if.py', '5', '3'] 5 [root@mysql Scripts]# python if.py davinder singh 3 ['if.py', 'davinder', 'singh'] davinder

count arguments

#!/usr/bin/python import sys print len(sys.argv) OUTPUT: [root@mysql Scripts]# python argu.py 1 [root@mysql Scripts]# python argu.py 3 2 [root@mysql Scripts]# python argu.py 3 2 3 [root@mysql Scripts]# python argu.py 3 2 4 4 [root@mysql Scripts]# python argu.py 3 2 4 6 5 [root@mysql Scripts]# python argu.py 3 2 4 6 7 8 7

Python: declare variables and printing

#!/usr/bin/python my_name = "davinder" my_age = 35 my_designation = "Lead Architect" my_weight = 82 my_eyes = "black" my_hairs = "black" print "Let's talk about %s." % my_name print "Let's talk about %d." % my_age print "My hairs color is %s." % my_hairs OUTPUT: #./variables.py Let's talk about davinder. Let's talk about 35. My hairs color is black.  

The Cisco Three-Layered Hierarchical Model

Image
Cisco has defined a hierarchical model known as the hierarchical internetworking model. This model simplifies the task of building a reliable, scalable, and less expensive hierarchical internetwork because rather than focusing on packet construction, it focuses on the three functional areas, or layers, of your network:   Core layer : This layer is considered the backbone of the network and includes the high-end switches and high-speed cables such as fiber cables. This layer of the network does not route traffic at the LAN. In addition, no packet manipulation is done by devices in this layer. Rather, this layer is concerned with speed and ensures reliable delivery of packets.   Distribution layer : This layer includes LAN-based routers and layer 3 switches. This layer ensures that packets are properly routed between subnets and VLANs in your enterprise. This layer is also called the Workgroup layer. Access layer : This layer includes hubs and switches. This layer is also calle...