Posts Tagged ‘python’

Python Application 4 – Replace Text Content

 
Step 1
 
Open any text editor (gedit,pico,vi,nano) then enter the following python script and save the file with .py extension.
 
#!/usr/bin/python
#Author : Jijo K Jose
 
print "\n————————————\nChapter 22 – Regular Expression 5 \n————————————\n"
 
import re
 
in_str = raw_input("Enter a text         : ")
 
se_str = raw_input("Enter search string  : ")
 
re_str = raw_input("Enter replace string : ")
 
count = 10
 
reg1 = re.compile(se_str)
 
print "Result : ",reg1.sub(re_str,in_str,count)
 
print "\n———————————–\n"
 
#END

Read more »

Python Application 3 – Check Email Address

 
Step 1
 
Open any text editor (gedit,pico,vi,nano) then enter the following python script and save the file with .py extension.
 
#!/usr/bin/python
#Author : Jijo K Jose
 
print "\n————————————\nChapter 20 – Regular Expression 4 \n————————————\n"
 
import re
 
in_str = raw_input("Enter an email address : ")
 
se_str = "\w+@\w+\.[com|in|org|net]"
 
reg1 = re.compile(se_str)
 
search1 = reg1.search(in_str)
 
if search1:
 print "\nValid email address"
else:
 print "\nInvalid email address"
 
print "\n———————————–\n"
 
#END

Read more »

Python Application 2 – Extract File Content

 
Step 1
 
Open any text editor (gedit,pico,vi,nano) then enter the following python script and save the file with .py extension.
 
#!/usr/bin/python
#Author : Jijo K Jose
 
f1 = open("logfile","r")
 
for i in f1.readlines():
 j = i.split(' ')
 print j
 
#END

Read more »