To Get Started Django

In Django the to create a new project use the command:


django-admin.py startproject "Project name"

After this their will a folder created at the same directory with the project name given. And there will 4 files created they are

django_bookmarks/
__init__.py
manage.py
settings.py
urls.py

To run a server using django:

use the command : python manage.py runserver (where  we run the browser using localhost:8000 the first django website gets started.)
 



MySqldb python installation

Hi please have a check I have installed the pythons mysql version with the following command.


sudo yum install MySql-python

how to change the mysql password for root

1. sudo service mysqld stop

2.mysqld_safe --skip-grant-tables

3.open a new terminal

4.update user set Password=PASSWORD(‘new-password’) WHERE User=’root’; 

How to start Restart and stop httpd

to start httpd :

service httpd start

to restart:

service httpd restart

to stop:

service httpd stop

A Simple while loop program in python

Hi everyone today I have tried while condition to  excercise on conditional statements . here are some of the programs I have tried.

answer = raw_input(" guess a lucky number between 0 - 9 :")
while answer!='5':
print ("Guess the number again !")
answer = raw_input("guess a lucky number between 0 - 9 :")
else:
print "The answer is correct"

 

print "Which city is capital of spain"
counter = 1
while counter <= 5:
city = raw_input("The Guess no  " + str(counter) + " is ")
if city != 'madrid':
print "Good Try But try again, its not correct"
else:
print "Good guess! at your %d  chance" % counter
break
counter = counter +1
else:
print "Game over your chances ended"


 

 

Regular Expressions in Python

A regular expression search is typically written as : -
  match = re.search(pat, str)

A Python Program to Print colors in shapes you like

def rectangle():
color = raw_input("Enter a color you like : ")
color1 = (color + " ")*10
color2 = color + (" "*(len(color1)-(2*(len(color))+1))) + color
print color1
print color2
print color2
print color1
def square():
color = raw_input("Enter a color you like : rectangle or square ")
color1 = (color + " ")*5
color2 = color + (" "*(len(color1)-(2*(len(color))+1))) + color
print color1
print color2
print color2
print color2
print color2
print color2
print color1
__diagram__ = raw_input("Enter the dia ")
if __diagram__=="rectangle":
rectangle()
elif __diagram__=="square":
square()

Some Cartoons Using Python

print"""
\t  ________
\t | --  -- |
\t |  @   @ |
\t |   ---  |
\t |________|
"""

 

print"""
\t    _____
\t __/__|__\___
\t|_____|___|__|
\t'-@-------@--'
\t
"""
print """
\t\\ | /
\t @ @
\t *
\t \\\"\"\"/
"""

A Simple python program to convert farenheit to Celcius

F = int(raw_input("Enter temp in Farenheit : "))
C = (F - 32)* 5/9
print C

python Program with numbers

Hi here I have tried a math program . In which we should get result as -2 for any number that have been given as input

num = int(raw_input("Input any number u like :"))
cal = ((num + 3 ) * 2) - 4
new = ( 2 * (num) ) - cal
print num
print cal
print new

A word count program using Dictionary

hi today I have tried a file program to fine the word counts in a file

 

def fileprogram(filename):
f=open(filename,'r')
wordcount=0
for lines in f:
f1=lines.split()
wordcount=wordcount+len(f1)
f.close()
print 'word count:', str(wordcount)
fileprogram(raw_input("enter file name:"))

Dictionary Hash Table

hi please have a check i have tried some commands with the dictionary in python

 

designs = {}
designs['c'] = 'circle'
designs['r'] = 'rectangle'
designs['o'] = 'oval'
designs['s'] = 'sqaure'
print designs['o']
#designs['o'] = 6
'o' in designs
if 'z' in designs: print designs['z']
print designs.get('z')
for key  in designs: print key
for key in designs.keys(): print key
print designs.keys()
print designs.values()
for key in sorted(designs.keys()):
print key,designs[key]
print designs.items()
for a,v in designs.items(): print a, '>', v

Sorting command in python

a = [5, 2, 4, 5]
print sorted(a)
print a
strs = ['Green','Red', 'Blue','white','violet']
print sorted(strs)
print sorted(strs, reverse=True)
print sorted(strs, key=len)
print sorted(strs, key=str.lower)
def MyFn(s):
return s[-1]
print sorted(strs, key=MyFn)
squares = [ n * n for n in a]
mac = ['hi', 'Everyone']
shout = [s.upper() + '!!!' for s in mac]
colorsa = [ s.upper() for s in strs if 'e' in s]
print colorsa
print colorsb
print shout
print squares
print strs.sort()
btuple = (1,2,'hi')
print len(btuple)

Build in methods available for lists

Hi here I have tried to create a program to use all the methods used in a list :

 

colors = ['Green','Red', 'Blue','white','violet']
fruits = ['mango','grape','orange']
colors.append('Yello')
print colors
colors.insert(4,"rose")
print colors
colors.extend(fruits)
print colors
print colors.index('rose')
colors.remove('grape')
print colors
colors.pop(1)
print colors

Build in string Methods available for python.

Hi Everyone , Today I tried to use  most of string methods in a program itself . Here is what I have done:

 

import sys
import os
def main():
a = raw_input("Enter a name: ")
print a.capitalize()
print a.lower()
print a.upper()
print a.strip( )
print a.strip( ' ' );
print a.lstrip('t')
print a.isalpha()
print a.isdigit()
print a.isspace()
print a.startswith('t')
print a.endswith('a')
print a.find('a')
print a.replace('a','XYZ')
print a.split(' ',1)
print a.join('')
print a.partition('A')
print a.translate(None, 'aeiou')
if __name__ == '__main__':
main()

User Config Files

we can do the user configuration as normal user itself . For eg.

when we give the command ls -a at normal user we could see the .bashprofile and .bashrc files are the configuration files for the bash shell. The bash shell is like a intermediate between the operating system and user.

Super User Account in Linux, the su command

The super user account can be called by giving the su command and where we should give the password over there. The name of the super account is the root.

cd / by giving this command we can move to the very top level directory. And when we give the ls there we could see some sub level directories over there.

bin    -  [ cd bin ] [  ls ]     The bin directory i.e, the binary directory over there would have the most common  executable files over there. For eg like cat , pwd , vi etc.

opt - the opt directory is where we install the optional software

root - the root directory is root users home directory

sbin - contains system executable files

Manpage vs Info page in linux And the ls command in Linux

The Man command in Linux stands for Manual

To scroll down the linux shell use spacebar. When we give the man ls command we could see the information about the files in it .And  we could see the synopsis of how to use the command. And also we could see the various options avaible in it.

For eg : the  - a command over there lists the entire files including user created.

- l command is used to list the entire files with the details of when created file type etc.

Now lets see some of the linux commands :

ls                     -    this lists the directory files

ls  -a              -   this command lists the entire files in the directory . Here we could see user config files like        .bash_history - which contains the info   of     the   commands given in shell (i.e,) when we scrolldown we get the list of commands we typed in shell due to this file. And also we could see the.gnome file which contains the directory configuration files

ls -l              - this command lists the files excluding the .doc files . And we could get information of the date it was created and the user privelages of it etc.

ls -al          - this command gives the entire file info including the .doc files.

Now lets see the Info command

info ls     - command would give the entire document of the ls command.

In in the Info page you could see the entire the menu option where when w give the ENTER key over there we could get the detailed info of the commands . And to search for any keywords we should use the CNTRL + S . When we give CNTRL + S again and again we could go the next  instances of keywords . To stop searching use CNTRL + G . And to quit info page use q .

 

And where as in Man page its like vi window , where we could see the : over there . And here to search give /  instead of : and then give the keyword  there  and press ENTER we could get the instance of that keyword.

 

The Info pages are useful to learners and Man pages are useful for experienced users