Dealing with Python basics
"""This page covers max all the topicsconditional , loops , format string , string functions , listsDictionaries , files , directory , functions , definitions ,modules , Exception handlingRemaining parts is covered in next post"""for y in xrange(1,10):print yprint [1,2,3] * 3a,b,c = 3,5,6print a,b,codd = [1,3,5,7,9]even = [2,4,6,8,10]print odd+even# string formattingform = ("john","jell",3.14)fs = "hello"print "%s hai %s king %d" % (fs,form[1],form[2])# String formatting with listmylis = [1,2,3]print "This is my list %s" % (mylis)# Now we will go for basic string operationsone = "kri.sh.cdb.ry"print "The length of the string %s" %(len(one))print "The index of h %s" %(one.index("h"))print "The count of letter r %s" %(one.count("r"))print "In capslock %s and the Lowerlock %s" %(one.upper(),one.lower())print "The sub string %s" %(one[0:5])print "They start with = %s and ends with = %s" %(one.startswith("kris"),one.endswith("ry"))print "The splitting %s" %(one.split("."))# Now goes with operations like boolesn comparison etc..name = "John"age = 23if age == 2 and name == "John":print "ok"else:print "no ok"i = 1while (i<10):print ii=i+1name,king = "krishcdbry","krishcdbry"if name in[king]:print "yess"if name is king:print "hey"count = 1while True:print countcount += 1if count > 5:breakc=0while True:c += 1if c%2==0:continueif c>5:breakprint c# Functiondef my_krish(n):print "hello krish the number is %s" %(n)def one_add(a,b):my_krish(a+b)def one_main(name1,name2):print "Hello dudes %s and %s" %(name1,name2)one_main("krishcdbry","kingcdbry")one_add(5,3)# Going to objects and classesclass Krish:car_name,car_cost,color = "Ferrari",7000000,"blue"car_one = Krish()car_one.car_name , car_one.car_cost,car_one.color = "Buggati",10000000,"Merun"print Krish().colorprint car_one.color# Dictionarieskrishbook = {"krish":909090909,"Mohan": 964298874}# ORkrishbooks = {}krishbooks["name"] = 9099900krishbooks["one"] = 00123213123for name, number in krishbooks.iteritems():print "Phone number of %s is %d" % (name, number)del krishbook["krish"]print krishbookkrishbooks.pop("one")print krishbooks# Dealing with files""" Creating the file not exists """fi = open("new.txt","wb")fi.write("Hello this is krishcdbry's file buddy \n \n \n and This is just a cool python script");fi.close()""" Reading the file """fi = open("new.txt","r+")str = fi.read()print " Reading the file = %s "%(str)fi.tell() # Tells the position of the cursorfi.seek(0,10) # Repositioning the cursorfi.close() # closes the file# Renaming the file name# importing the OS module will helps to rename the filesimport os # this imports the os module....!os.rename("old_file_name.txt","new_name.txt")# We can remove the file .. simply deleteos.remove("file_name")# mkdir - for making new directory.....!os.mkdir("new_dir")# chdir - change the dir......!os.chdir("dir_name")# pwd current working directory...!os.getcwd()# rmdir - remove the directoryos.rmdir("dir_name")# Exception handlingtry:fh = open("jahe.txt","r+")fh.write("Hai this is another file....!")except IOError:print "Their is no file found with name jahe.txt check it once buddy"else:print "File found dude"# raise - we can raise Exceptiondef function_name(level):if level<1:raise "Their is an error in this level"# the code below would not be executre if we raise this exception
Monday, 4 August 2014
PYTHON BASICS
Friday, 4 July 2014
GENERATING PUBLIC & PRIVATE KEY
GENERATING KEYS
In linux we can create public and private key
STEP 1 : Checking the ssh directory. So Just open the terminal and then type the below command
$ cd ~/.sshIf the directory is present then you will get into it , now it is easy to create apair of public and private keys with just one command
$ ssh-keygen
$ Enter passphrase (empty for no passphrase): [Type a passphrase]
# Enter same passphrase again: [Type passphrase again]
Hence your public key and private keys are generated. Just check them by typing the following commmand.
$ ls -lNow you will find the files like id_rsa , id_rsa.pub , known_hosts.
id_rsa : Private key
id_rsa.pub : Public key
Hence your keys successfully generated
TASK MANAGER IN LINUX
WE CAN FIND THE RUNNING PROCESS AND CAN KILL THEM BY FOLLOWING 2 STEPS
STEP 1 : Type "TOP" command in terminal.
$ sudo -s
$ [sudo] password for username : (type your password here)
$ top
STEP 2 : Find the particular process and then it's respective id.Let us assume the process id as 12043 , then command goes like this
$ kill 12043
NODE.JS - PART 2 (DOWNLOAD & INSTALL)
NODE.JS
First we need to download NODE.JS
Version : v0.10.29
Download Links:
Windows Installer (.msi)
32-bit Click here
64-bit Click here
Windows Binary (.exe)
32-bit Click here
64-bit Click here
Mac OS X Installer (.pkg)
Universal Click here
Mac OS X Binaries (.tar.gz)
32-bit Click here
64-bit Click here
Linux Binaries (.tar.gz)
32-bit Click here
64-bit Click here
First we need to download NODE.JS
Version : v0.10.29
Download Links:
Windows Installer (.msi)
32-bit Click here
64-bit Click here
Windows Binary (.exe)
32-bit Click here
64-bit Click here
Mac OS X Installer (.pkg)
Universal Click here
Mac OS X Binaries (.tar.gz)
32-bit Click here
64-bit Click here
Linux Binaries (.tar.gz)
32-bit Click here
64-bit Click here
IN LINUX & MAC
After downloading go to the folder containing the node's tar.gz file (Downloaded file)
Run these commands:
1.Extarct the tar.gz file
3.The configure and install
Successfully installed node in Linux
1.Extarct the tar.gz file
$ tar -xzf node-v0.10.29.tar.gz2.Go to the extarcted folder$ cd node-v0.10.29.3.The configure and install
$ ./configure
$ sudo make install
Successfully installed node in Linux
IN WINDOWS
Directly we can install the .exe file or .msi file , here the entire installation is in the similar way of installing a software.
After installtion we will get two things
1.Node.js Command prompt
2.Node.exe

After installtion we will get two things
1.Node.js Command prompt
2.Node.exe
Successfully installed node in your windows.
Subscribe to:
Comments (Atom)






