python -m pip install cx_Oracle
import cx_Oracle
conn =cx_Oracle.connect('training/ADMIN123@LOCALHOST')
cursor =[Link]();
[Link]("Create table student_t(Student_id number,student_name
varchar2(20),city varchar2(20))")
print("Create table Successfull")
[Link]()
[Link]()
-------------------------------------------------------------
import cx_Oracle
conn =cx_Oracle.connect('training/ADMIN123@LOCALHOST')
cursor =[Link]();
[Link]("insert into student_t values(100,'babjee','chennai')")
print("Create table Successfull")
[Link]()
[Link]()
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=[Link]()
for row in [Link](sql):
for i in range(len(row)):
print(str(row[i]).ljust(column_length[i]), end='')
print()
[Link]()
----------------------------------------------------------------
from openpyxl import load_workbook
wb =load_workbook("d:/demo/[Link]")
sheet =[Link]
for row in sheet.iter_rows(min_row=1, min_col=1, max_row=4, max_col=2):
for cell in row:
print([Link], end=" ")
print()
----------------------------------------------------------------
The re module offers a set of functions that allows us to search a string for a
match:
findall Returns a list containing all matches
search Returns a Match object if there is a match anywhere in the string
split Returns a list where the string has been split at each match
sub Replaces one or many matches with a string
---------------------------------------------------------------
Metacharacters
Metacharacters are characters with a special meaning:
[] A set of characters "[a-m]"
\ Signals a special sequence (can also be used to escape special characters)
"\d"
. Any character (except newline character) "he..o"
^ Starts with "^hello"
$ Ends with "world$"
* Zero or more occurrences "aix*"
+ One or more occurrences "aix+"
{} Exactly the specified number of occurrences "al{2}"
| Either or "falls|stays"
Find all lower case characters alphabetically between "a" and "m":
import re
txt = "The rain in Spain"
x = [Link]("[a-m]", txt)
print(x)
----------------------------------------------------------------
#Find all digit characters:
import re
txt = "That will be 59 dollars"
x = [Link]("\d", txt)
print(x)
----------------------------------------------------------------
#Search for a sequence that starts with "he", followed by two (any) characters, and
an "o":
import re
txt = "hello world"
x = [Link]("he..o", txt)
print(x)
---------------------------------------------------------------
#Check if the string starts with 'hello':
import re
txt = "hello world"
x = [Link]("^hello", txt)
if x:
print("Yes, the string starts with 'hello'")
else:
print("No match")
----------------------------------------------------------------
#Check if the string contains "ai" followed by 0 or more "x" characters:
import re
txt = "The rain in Spain falls mainly in the plain!"
x = [Link]("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 = [Link]("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
txt = "The rain in Spain falls mainly in the plain!"
x = [Link]("al{2}", txt)
print(x)
if x:
print("Yes, there is at least one match!")
else:
print("No match")
---------------------------------------------------------------
#Check if the string contains either "falls" or "stays":
import re
txt = "The rain in Spain falls mainly in the plain!"
x = [Link]("falls|stays", txt)
print(x)
if x:
print("Yes, there is at least one match!")
else:
print("No match")
----------------------------------------------------------------
\A Returns a match if the specified characters are at the beginning of the
string "\AThe"
\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
txt = "The rain in Spain"
x = [Link]("\AThe", txt)
print(x)
if x:
print("Yes, there is a match!")
else:
print("No match")