Python
Python
import cx_Oracle
conn =cx_Oracle.connect('training/ADMIN123@LOCALHOST')
cursor =conn.cursor();
cursor.execute("Create table student_t(Student_id number,student_name
varchar2(20),city varchar2(20))")
print("Create table Successfull")
cursor.close()
conn.close()
-------------------------------------------------------------
import cx_Oracle
conn =cx_Oracle.connect('training/ADMIN123@LOCALHOST')
cursor =conn.cursor();
cursor.execute("insert into student_t values(100,'babjee','chennai')")
print("Create table Successfull")
cursor.close()
conn.close()
import cx_Oracle
conn =cx_Oracle.connect("training","ADMIN123",'localhost/xe')
sql ="select empno,ename,job,sal from emp"
column_length=[6,10,9,8]
cursor=conn.cursor()
for row in cursor.execute(sql):
for i in range(len(row)):
print(str(row[i]).ljust(column_length[i]), end='')
print()
cursor.clouse()
----------------------------------------------------------------
from openpyxl import load_workbook
wb =load_workbook("d:/demo/emp.xlsx")
sheet =wb.active
for row in sheet.iter_rows(min_row=1, min_col=1, max_row=4, max_col=2):
for cell in row:
print(cell.value, end=" ")
print()
----------------------------------------------------------------
The re module offers a set of functions that allows us to search a string for a
match:
---------------------------------------------------------------
Metacharacters
Metacharacters are characters with a special meaning:
Find all lower case characters alphabetically between "a" and "m":
import re
x = re.findall("[a-m]", txt)
print(x)
----------------------------------------------------------------
import re
x = re.findall("\d", txt)
print(x)
----------------------------------------------------------------
#Search for a sequence that starts with "he", followed by two (any) characters, and
an "o":
import re
import re
import re
txt = "The rain in Spain falls mainly in the plain!"
x = re.findall("aix*", txt)
print(x)
if x:
print("Yes, there is at least one match!")
else:
print("No match")
---------------------------------------------------------------
#Check if the string contains "ai" followed by 1 or more "x" characters:
import re
txt = "The rain in Spain falls mainly in the plain!"
x = re.findall("aix+", txt)
print(x)
if x:
print("Yes, there is at least one match!")
else:
print("No match")
-------------------------------------------------------------
#Check if the string contains "a" followed by exactly two "l" characters:
import re
\b Returns a match where the specified characters are at the beginning or at the
end of a word
\B Returns a match where the specified characters are present, but NOT at the
beginning (or at the end) of a word
\d Returns a match where the string contains digits (numbers from 0-9) "\d"
\D Returns a match where the string DOES NOT contain digits "\D"
\s Returns a match where the string contains a white space character "\s"
\S Returns a match where the string DOES NOT contain a white space character
"\S"
\w Returns a match where the string contains any word characters (characters
from a to Z, digits from 0-9, and the underscore _ character) "\w"
\W Returns a match where the string DOES NOT contain any word characters "\W"
\Z Returns a match if the specified characters are at the end of the string
"Spain\Z"
import re
x = re.findall("\AThe", txt)
print(x)
if x:
print("Yes, there is a match!")
else:
print("No match")