diff --git a/database/createdb.py b/database/createdb.py new file mode 100644 index 0000000..3783841 --- /dev/null +++ b/database/createdb.py @@ -0,0 +1,23 @@ +import pymysql + +# Open database connection +db = pymysql.connect("localhost","root","admin","py_work" ) + +# prepare a cursor object using cursor() method +cursor = db.cursor() + +# Drop table if it already exist using execute() method. +cursor.execute("DROP TABLE IF EXISTS EMPLOYEE") + +# Create table as per requirement +sql = """CREATE TABLE NEWDATA ( + FIRST_NAME CHAR(20) NOT NULL, + LAST_NAME CHAR(20), + AGE INT, + SEX CHAR(1), + INCOME FLOAT )""" + +cursor.execute(sql) + +# disconnect from server +db.close() diff --git a/database/mysql.py b/database/mysql.py new file mode 100644 index 0000000..8ef5e79 --- /dev/null +++ b/database/mysql.py @@ -0,0 +1,7 @@ +import pymysql +connection = pymysql.connect(host='localhost',user='root',passwd='admin',db='py_work') +cursor=connection.cursor() +sql=('select * from Persons') +cursor.execute(sql) +data=cursor.fetchall() +print(data) diff --git a/files/New folder/copy.py b/files/New folder/copy.py new file mode 100644 index 0000000..9076c2e --- /dev/null +++ b/files/New folder/copy.py @@ -0,0 +1,4 @@ +with open('text.txt','r')as rf: + with open('test_copy.txt','w')as wf: + for line in rf: + wf.write(line) diff --git a/files/New folder/open.py b/files/New folder/open.py new file mode 100644 index 0000000..5e6cc19 --- /dev/null +++ b/files/New folder/open.py @@ -0,0 +1,9 @@ +f = open("text.txt","r") + +t=f.read() + +print(t) +f.close() + + + diff --git a/files/New folder/test2.txt b/files/New folder/test2.txt new file mode 100644 index 0000000..e6dc6da --- /dev/null +++ b/files/New folder/test2.txt @@ -0,0 +1 @@ +relcome \ No newline at end of file diff --git a/files/New folder/text.txt b/files/New folder/text.txt new file mode 100644 index 0000000..55cf20b --- /dev/null +++ b/files/New folder/text.txt @@ -0,0 +1 @@ +hi this is vasanth!! \ No newline at end of file diff --git a/files/New folder/write.py b/files/New folder/write.py new file mode 100644 index 0000000..bdbc609 --- /dev/null +++ b/files/New folder/write.py @@ -0,0 +1,6 @@ +with open('test2.txt','w')as f: + f.write('Welcome') + #f.seek(0) + #f.write('r') + f.write('Welcome') + diff --git a/files/read.py b/files/read.py new file mode 100644 index 0000000..af47f2a --- /dev/null +++ b/files/read.py @@ -0,0 +1,4 @@ +file = open("C:\\Users\\vasan\\OneDrive\\Desktop\\test.txt","r") +for line in file: + x = line.split(",") + print(x[0],'\t',x[2]) diff --git a/files/test.txt b/files/test.txt new file mode 100644 index 0000000..65ebc98 --- /dev/null +++ b/files/test.txt @@ -0,0 +1,3 @@ +Hi !!, how are you, nice to meet you +Hello World!!,python programming, really +This is Vasanth Nagarajan !!!,file operations, move diff --git a/functions/fucntion2.py b/functions/fucntion2.py new file mode 100644 index 0000000..0bd13fe --- /dev/null +++ b/functions/fucntion2.py @@ -0,0 +1,7 @@ +# This is theanother progrma for the function defining the name + +def hello(name): + print('Hello '+ name) + +hello('vasanth') +hello('nagarajan') diff --git a/functions/hellofunction.py b/functions/hellofunction.py new file mode 100644 index 0000000..93d9cd2 --- /dev/null +++ b/functions/hellofunction.py @@ -0,0 +1,11 @@ +# This is the simplest program to create a function + + +def hello(): + print('Hello World!') + print('Hello world!!') + print('Hello World@@@@') + +hello() +hello() +hello() diff --git a/functions/ran.py b/functions/ran.py new file mode 100644 index 0000000..2545ab7 --- /dev/null +++ b/functions/ran.py @@ -0,0 +1,4 @@ +import random + +for i in range(5): + print(random.randint(1,50)) diff --git a/functions/random.py b/functions/random.py new file mode 100644 index 0000000..4f4597f --- /dev/null +++ b/functions/random.py @@ -0,0 +1,6 @@ +# This program is about Random variable + +import random + +for i in range(10): + print(random.randint(1,10)) diff --git a/inheritance/parentclass.py b/inheritance/parentclass.py new file mode 100644 index 0000000..09204d1 --- /dev/null +++ b/inheritance/parentclass.py @@ -0,0 +1,22 @@ +class Parent: + def __init__(self): + print("This is the parent class") + def parentFunc(self): + print("This is the parent func") + +p = Parent() +p.parentFunc() + + +#Child Class +class Child(Parent): + def __init__(self): + print("This is the Child Class") + def childFunc(self): + print("This is the Child func") +c = Child() +c.childFunc() + +#Child calls the parent function +c.parentFunc() + diff --git a/myname.py b/myname.py new file mode 100644 index 0000000..6e450b9 --- /dev/null +++ b/myname.py @@ -0,0 +1,54 @@ +#print the last letter from myname + +myname = input("Enter you name:") +#print(myname[-1]) +''' +print(myname[0]) +print(myname[1]) +print(myname[2]) +print(myname[3]) +print(myname[4]) +''' +#Method1 +#LIST +newarray = [] +oddcount = 0 +evencount = 0 +for i in range(len(myname)): + print (myname[i]) + newarray.append(i) + newarray.append(myname[i]) + + +print ("New Array from Myname..",newarray) +result = 0 +for i in newarray: + if type(i) == int: + result = result + i +print("SUM of interger numbers from Array..",result) +#ODDEVEN +for i in range(len(newarray)): + if i % 2 == 0: + evencount = evencount + 1 + else: + oddcount = oddcount + 1 +print ("ODD position values",evencount) +print ("Even Position values",oddcount) +#Tuple +tuplearray = [] +#expected output = [(0,'K'),(1,'G')] +for i in range(len(myname)): + tuplearray.append((i,myname[i])) + +print("New tuple from myname",tuplearray) +#dictionary +newdict = {} +for i in range(len(myname)): + newdict[i] = myname[i] +print("New dict from myname",newdict) +print (newdict[0]) +''' +#mentod2 +for i in myname: + print (i) +''' diff --git a/python with access/Database1.accdb b/python with access/Database1.accdb new file mode 100644 index 0000000..0b80389 Binary files /dev/null and b/python with access/Database1.accdb differ diff --git a/python with access/con2.py b/python with access/con2.py new file mode 100644 index 0000000..f818aa7 --- /dev/null +++ b/python with access/con2.py @@ -0,0 +1,11 @@ +import pypyodbc + +# Create Connection +con = pypyodbc.connect('DRIVER={Microsoft Access Driver (*.mdb)};UID=admin;UserCommitSync=Yes;Threads=3;SafeTransactions=0;PageTimeout=5;MaxScanRows=8;;MaxBufferSize=2048FIL={MS Access};DriverId=25;DefaultDir=C:/Users/vasan/OneDrive/Documents;DBQ=C:/Users/vasan/OneDrive/Documents/Database2.mdb;') + +cursor = con.cursor() + +cursor.execute("SELECT * FROM details") + +for row in cursor.fetchall(): + print(row) diff --git a/python with access/connn.py b/python with access/connn.py new file mode 100644 index 0000000..267e898 --- /dev/null +++ b/python with access/connn.py @@ -0,0 +1,11 @@ +import pypyodbc + +# Create Connection +con = pypyodbc.connect('DRIVER={Microsoft Access Driver (*.mdb)};UID=admin;UserCommitSync=Yes;Threads=3;SafeTransactions=0;PageTimeout=5;MaxScanRows=8;;MaxBufferSize=2048FIL={MS Access};DriverId=25;DefaultDir=C:/Users/vasan/OneDrive/Documents;DBQ=C:/Users/vasan/OneDrive/Documents/Database1.mdb;') + +cursor = con.cursor() + +cursor.execute("SELECT * FROM contacts") + +for row in cursor.fetchall(): + print(row) diff --git a/python with access/ms access package.txt b/python with access/ms access package.txt new file mode 100644 index 0000000..58a6825 --- /dev/null +++ b/python with access/ms access package.txt @@ -0,0 +1,14 @@ +pip install pyodbc +pip install pypyodbc + +import pypyodbc + +# Create Connection +con = pypyodbc.connect('DRIVER={Microsoft Access Driver (*.mdb)};UID=admin;UserCommitSync=Yes;Threads=3;SafeTransactions=0;PageTimeout=5;MaxScanRows=8;;MaxBufferSize=2048FIL={MS Access};DriverId=25;DefaultDir=C:/Users/vasan/OneDrive/Documents;DBQ=C:/Users/vasan/OneDrive/Documents/Database2.mdb;') + +cursor = con.cursor() + +cursor.execute("SELECT * FROM contacts") + +for row in cursor.fetchall(): + print(row)