Dummy Python Project
Dummy Python Project
1
ACKNOWLEDGEMENT
SAHADRI JAIN
(XII Commerce)
2
CONTENTS
3
USER DEFINED FUNCTIONS
[Link] a Function
In Python a function is defined using the def keyword:
eg:
def my_function():
print(“Hello you are creating a function”)
[Link] a Function
To call a function, use the function name followed by parenthesis:
eg:
def my_function():
print(“Hello you are creating a function”)
my_function()
[Link]
Information can be passed into function as arguments.
Arguments are specified after the function name,inside the [Link]
can add as many arguments as you want, just separate them with a comma.
4
The following example has a function with one argument (fname).When the
function is called, we pass along a first name, which is used inside the
function to print the full name:
eg:
def my_function(fname):
print(fname + “Agrawal”)
my_function(“Anjali”)
my_function(“Aashi”)
my_function(“Raj”)
Parameters or Arguments?
A parameter is the variable listed inside the parentheses in the function
definition. An argument is the value that are sent to the function when it is
called.
Number of Arguments
By default, a function must be called with the correct number of arguments.
Meaning that if your function expects 2 arguments, you have to call the
function with 2 arguments, not more, and not less.
eg:
This function expects 2 arguments and gets 2 arguments.
def my_function(fname, lname):
print(fname + “” + lname)
my_function(“Anjali”, “Agrawal”)
5
If you try to call the function with 1 or 3 arguments, you will get an error:
eg:
This function expects 2 arguments but gets only 1.
def my_function(fname, lname):
print(fname + “” + lname)
my_function(“Anjali”)
[Link] Values
To let a function return a value, use return the statement:
eg:
def my_function(a):
return 5 * a
print(my_function(3))
print(my_function(5))
print(my_function(9))
6
TEXT FILES
1. [Link]
Exception Handling:
Error handling in Python is done through the use of exceptions that are caught in try
blocks and handled in except blocks.
Syntax:
try:
# statement that may raise error
except:
# handle exception here
finally:
# statement that will always run
Raising an Exception :
You can raise an exception in your program by using your own statement:
raise exception[, value]
Raising an exception breaks current code execution and returns the exception
back until it is handled.
7
Example:
Some Exceptions
ValueError() Raised when the built-in function for a data type has the
valid type of arguments, but the arguments have invalid values
8
Generators
A generator is simply a function which returns an object on which you can call next,
such that for every call it returns some value, until it raises a StopIteration exception,
signaling that all values have been generated. Such an object is called an iterator.
Normal functions return a single value using return, just like in Java. In Python,
however, there is an alternative, called yield. Using yield anywhere in a function makes
it a generator
EXAMPLE:
>>> def myGen(n):
... yield n
... yield n + 1
...
>>> g = myGen(6)
>>> next(g)
6
>>> next(g)
7
2. R_W.txt
Opening :
The first thing to do when you are working with files in Python isto open thefile. When
you open the files, you can specify with parameters how you want to open them.
The "r" is for reading, the "w" for writing and the "a" for appending.
9
Read mode:
fh=open(“filename_here”, “r”)
This opens the filename for reading. By default, the file is opened with the "r"
parameter.
Write mode:
fh = open("filename_here", "w")
This opens the the file for writing. It will create the file if it doesn't exist, and if it does,
it will overwrite it.
Append mode:
fh =open("filename_here", "a")
This opens the file in appending mode. That means, it will be open for writing and
everything will be written to the end of the file.
Closing:
It is always necessary to close a file when all the work is completed in order to prevent
it from external access and data loss.
[Link]()
This closes the file and is used when the program doesn't need it more.
Functions available for reading the files: read, readline and readlines.
10
read(): reads all characters (unless you specify other)
eg:
fh = open("filename", "r")
content = [Link]()
eg:
fh = open("filename", "r")
content = [Link]()
readlines(): returns a list containing all the lines of data in the file. The readlines
function reads all rows and retains the newlines character that is at the end of every row.
eg:
fh = open("filename", "r")
content = [Link]()
print [Link]()
print content[:-1]
eg:
fh = open("[Link]","w")
write("Hello World")
11
writeline(): write a list of strings to a file
eg:
fh = open("[Link]", "w")
lines_of_text = ["a line of text", "another line of text", "a third line"]
[Link](lines_of_text)
3. M_FUN.txt
Function defined in module:
A module allows you to logically organize your Python code. Grouping related code
into a module makes the code easier to understand and use. A module is a Python object
with arbitrarily named attributes that you can bind and reference.
Simply, a module is a file consisting of Python code. A module can define functions,
classes and variables. A module can also include runnable code.
Example:
The Python code for a module named aname normally resides in a file named
[Link].
return
You can use any Python source file as a module by executing an import statement in
some other Python source file. The import has the following syntax:
12
When the interpreter encounters an import statement, it imports the module if the
module is present in the search path. A search path is a list of directories that the
interpreter searches before importing a module. For example, to import the module
[Link], you need to put the following command at the top of the script -
>>>import support
support.print_func("Zara")
>>>Hello : Zara
A module is loaded only once, regardless of the number of times it is imported. This
prevents the module execution from happening over and over again if multiple imports
occur.
4. S_FUN.txt
String Manipulation Methods:
1. [Link]():
[Link]():
Return a copy of s, but with lower case letters converted to upper case
[Link](s[, chars]):
Return a copy of the string with leading characters removed. If chars is omitted or
None, whitespace characters are removed. If given and not None, chars must be a
string; the characters in the string will be stripped from the beginning of the string this
method is called on.
[Link](s[, chars]):
13
Return a copy of the string with trailing characters removed. If chars is omitted or
None, whitespace characters are removed. If given and not None, chars must be a
string; the characters in the string will be stripped from the end of the string this method
is call.
[Link](s):
Return a copy of s, but with upper case letters converted to lower case.
Return the lowest index in s where the substring sub is found such that sub is wholly
contained in s[start:end]. Return -1 on failure. Defaults for start and end and
interpretation of negative values is the same as for slices.
[Link]():
This method checks if the string is in lowercase and returns true if all the characters are
in lowercase.
[Link]():
This method checks if all the characters in the string are in uppercase. If any character is
in lower case, it would return false otherwise true.
5. D_T.txt
DATA STRUCTURES :
1. ARRAY:
Array refers to a named list of finite number n of similar data elements. Each of the data
elements can be referenced respectively by a set of consecutive numbers, usually
0,1,2,3,4 . . . n .
e.g.
14
A array ar containing 10 elements will be referenced as
2. STACKS:
Stacks data structure refer to list stored and accessed in a special way,
where LIFO(Last In First Out) technique is followed. In stack insertion and deletion
take place at only one end called the top.
3. QUEUES:
4. LINKED LIST:
Linked lists are special list of some data elements linked to one another.
The logical ordering is represented by having each element pointing to
next element. Each element is called a 'node' which has the parts.
The INFO part which stores the information and the reference pointer part i.e stores
reference of next element.
[Link]:
Trees are multilevel data structures having a hierarchical relationship amongst its
element called 'node'. Topmost node is called node of the tree and bottom most node of
tree is called leaves of tree. Each node have some reference pointers pointing to node
below it.
15
6. [Link]
This project has been created to fulfill the requirement of the CBSE Senior Secondary
Examination Class XII for Informatics Practices. This project is been created by Anjali
Agrawal of class XII under the guidance of Mr. Brandavan Tyagi sir .This project is
aimed to build a contact management system.
INTRODUCTION TO PROJECT
This GUI based Contact Management system provides the simplest management
of contact details. In short, this projects mainly focus on CRUD (Create Read
Update Delete) operations. There’s an external database connection file used in
this mini project to save user’s data permanently.
16
Features of this project:
1. Add Contacts
2. List Contacts
3. Update Contacts
4. Delete Contacts
Modules used:
1. Tkinter
Tkinter is the standard GUI library for Python. Python when combined with Tkinter
provides a fast and easy way to create GUI applications. Tkinter provides a powerful
Creating a GUI application using Tkinter is an easy task. All you need to do is perform
eg:
import Tkinter
top = [Link]()
Tkinter Widgets
Tkinter provides various controls, such as buttons, labels and text boxes used in a GUI
There are currently following types of widgets in Tkinter. We present these widgets as
1. Button
2. Canvas
The Canvas widget is used to draw shapes, such as lines, ovals, polygons and
3. Checkbutton
4. Entry
The Entry widget is used to display a single-line text field for accepting
5. Frame
6. Label
The Label widget is used to provide a single-line caption for other widgets. It
7. Listbox
19
8. Menubutton
9. Menu
10. Message
The Message widget is used to display multiline text fields for accepting
11. Radiobutton
12. Scale
13. Scrollbar
14. Text
15. Toplevel
16. Spinbox
The Spinbox widget is a variant of the standard Tkinter Entry widget, which
20
17. PanedWindow
18. LabelFrame
19. tkMessageBox
2. Sqlite
What is SQLite
Serverless
Normally, an RDBMS such as MySQL, PostgreSQL, etc., requires a separate
server process to operate. The applications that want to access the database server use
TCP/IP protocol to send and receive requests. This is called client/server architecture.
21
SQLite does NOT work this way.
SQLite database is integrated with the application that accesses the database. The
applications interact with the SQLite database read and write directly from the database
files stored on disk.
22
Self-Contained
SQLite is self-contained means it requires minimal support from the operating system
or external library. This makes SQLite usable in any environments especially in
embedded devices like iPhones, Android phones, game consoles, handheld media
players, etc.
SQLite is developed using ANSI-C. The source code is available as a big sqlite3.c and
its header file sqlite3.h. If you want to develop an application that uses SQLite, you just
need to drop these files into your project and compile it with your code.
Zero-configuration
Because of the serverless architecture, you don’t need to “install” SQLite before using
it. There is no server process that needs to be configured, started, and stopped. In
addition, SQLite does not use any configuration files.
Transactional
All transactions in SQLite are fully ACID-compliant. It means all queries and changes
are Atomic, Consistent, Isolated, and Durable.
In other words, all changes within a transaction take place completely or not at all even
when an unexpected situation like application crash, power failure, or operating system
crash occurs.
23
SQLite distinctive features
SQLite uses dynamic types for tables. It means you can store any value in any column,
regardless of the data type.
SQLite is capable of creating in-memory databases which are very fast to work with.
SOURCE CODE
import sqlite3
[Link]("Contact List")
width = 700
height = 400
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
x = (screen_width/2) - (width/2)
y = (screen_height/2) - (height/2)
[Link](0, 0)
[Link](bg="#6666ff")
#============================VARIABLES=======================
============
FIRSTNAME = StringVar()
LASTNAME = StringVar()
GENDER = StringVar()
AGE = StringVar()
ADDRESS = StringVar()
25
CONTACT = StringVar()
#============================METHODS========================
=============
def Database():
conn = [Link]("[Link]")
cursor = [Link]()
fetch = [Link]()
[Link]()
[Link]()
def SubmitData():
26
result = [Link]('', 'Please Complete The Required Field',
icon="warning")
else:
[Link](*tree.get_children())
conn = [Link]("[Link]")
cursor = [Link]()
str([Link]())))
[Link]()
fetch = [Link]()
[Link]()
[Link]()
[Link]("")
[Link]("")
[Link]("")
[Link]("")
[Link]("")
[Link]("")
27
def UpdateData():
if [Link]() == "":
icon="warning")
else:
[Link](*tree.get_children())
conn = [Link]("[Link]")
cursor = [Link]()
[Link]()
fetch = [Link]()
[Link]()
[Link]()
[Link]("")
[Link]("")
[Link]("")
[Link]("")
28
[Link]("")
[Link]("")
def OnSelected(event):
curItem = [Link]()
contents =([Link](curItem))
selecteditem = contents['values']
mem_id = selecteditem[0]
[Link]("")
[Link]("")
[Link]("")
[Link]("")
[Link]("")
[Link]("")
[Link](selecteditem[1])
[Link](selecteditem[2])
[Link](selecteditem[4])
[Link](selecteditem[5])
[Link](selecteditem[6])
UpdateWindow = Toplevel()
[Link]("Contact List")
29
width = 400
height = 300
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
[Link](0, 0)
if 'NewWindow' in globals():
[Link]()
#===================FRAMES==============================
FormTitle = Frame(UpdateWindow)
[Link](side=TOP)
ContactForm = Frame(UpdateWindow)
[Link](side=TOP, pady=10)
RadioGroup = Frame(ContactForm)
#===================LABELS==============================
lbl_title.pack(fill=X)
lbl_firstname.grid(row=0, sticky=W)
lbl_lastname.grid(row=1, sticky=W)
lbl_gender.grid(row=2, sticky=W)
lbl_age.grid(row=3, sticky=W)
lbl_address.grid(row=4, sticky=W)
lbl_contact.grid(row=5, sticky=W)
#===================ENTRY===============================
[Link](row=0, column=1)
[Link](row=1, column=1)
[Link](row=2, column=1)
31
[Link](row=3, column=1)
[Link](row=4, column=1)
[Link](row=5, column=1)
#==================BUTTONS==============================
command=UpdateData)
#fn1353p
def DeleteData():
if not [Link]():
icon="warning")
else:
record?', icon="warning")
if result == 'yes':
curItem = [Link]()
contents =([Link](curItem))
32
selecteditem = contents['values']
[Link](curItem)
conn = [Link]("[Link]")
cursor = [Link]()
selecteditem[0])
[Link]()
[Link]()
[Link]()
def AddNewWindow():
global NewWindow
[Link]("")
[Link]("")
[Link]("")
[Link]("")
[Link]("")
[Link]("")
NewWindow = Toplevel()
[Link]("Contact List")
width = 400
height = 300
screen_width = root.winfo_screenwidth()
33
screen_height = root.winfo_screenheight()
[Link](0, 0)
if 'UpdateWindow' in globals():
[Link]()
#===================FRAMES==============================
FormTitle = Frame(NewWindow)
[Link](side=TOP)
ContactForm = Frame(NewWindow)
[Link](side=TOP, pady=10)
RadioGroup = Frame(ContactForm)
font=('arial', 14)).pack(side=LEFT)
#===================LABELS==============================
lbl_title.pack(fill=X)
lbl_firstname.grid(row=0, sticky=W)
lbl_lastname.grid(row=1, sticky=W)
lbl_gender.grid(row=2, sticky=W)
lbl_age.grid(row=3, sticky=W)
lbl_address.grid(row=4, sticky=W)
lbl_contact.grid(row=5, sticky=W)
#===================ENTRY===============================
[Link](row=0, column=1)
[Link](row=1, column=1)
35
[Link](row=2, column=1)
[Link](row=3, column=1)
[Link](row=4, column=1)
[Link](row=5, column=1)
#==================BUTTONS==============================
#============================FRAMES==========================
============
[Link](side=TOP)
36
[Link](side=TOP)
[Link](side=LEFT, pady=10)
[Link](side=LEFT)
[Link](side=RIGHT, pady=10)
[Link](side=TOP)
#============================LABELS==========================
=
===========
width=500)
lbl_title.pack(fill=X)
#============================ENTRY===========================
============
#============================BUTTONS=========================
37
============
command=AddNewWindow)
btn_add.pack()
btn_delete.pack(side=RIGHT)
#============================TABLES==========================
=
===========
yscrollcommand=[Link], xscrollcommand=[Link])
[Link](command=[Link])
[Link](side=RIGHT, fill=Y)
[Link](command=[Link])
[Link](side=BOTTOM, fill=X)
[Link]()
[Link]('<Double-Button-1>', OnSelected)
#============================INITIALIZATION==================
============
if __name__ == '__main__':
Database()
[Link]()
39
40
INPUT/OUTPUT INTERFACE
41
42
43
44
45
BIBLIOGRAPHY
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
BIBLIOGRAPHY
61