Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

Thursday, September 10, 2015

Logging Module in Python

import logging
 
logging.basicConfig(filename="sample.log", level=logging.INFO)
log = logging.getLogger("ex")
 
try:
    raise RuntimeError
except Exception, err:
    log.exception("Error!")
 
 
You can find a good blog on Logging here:
 
http://www.blog.pythonlibrary.org/2012/08/02/python-101-an-intro-to-logging/ 

Sets in python

a = set(["Jake", "John", "Eric"])
b=set(["asas","sdsad","Eric"])

print a.intersection(b)
print a.difference(b)
print a.union(b)

Wednesday, July 8, 2015

File handlign in python



Reading ,Writing to a file in Python

fo = open("test.txt","w")
str1="This is a Test file written from Python Program"
fo.write(str1)
fo.close()
fo = open("test.txt","r")
str=fo.read(100)
print str
fo.close