Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- """good use of primitive built in functions to process whole files.
- invoked the script defines cat() takes a filename as argument opens
- and reads it as a single text file then Find() function is defined
- using regular expressions built in functions search() match() and group().
- Find() is called with Rose and text as arguments for testing. Next step
- is to prompt user for the search string pattern argument for Find()"""
- import sys
- import re
- def cat(filename):
- f = open(filename, 'rU')
- text = f.read()
- print '----------------->your file has been opened..'
- print text,
- print '----------------->searching pattern Roses'
- def Find(pat, text):
- match = re.search(pat, text)
- if match:
- print match.group()
- else:
- print 'not found'
- Find('Rose', text)
- f.close()
- #main() to dump file to screen
- def main():
- cat(sys.argv[1])
- #boilerplate main() call.
- if __name__=='__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment