import base64
encoded = base64.b64encode('life is very easy with python')
print encoded
data = base64.b64decode(encoded)
print data
bGlmZSBpcyB2ZXJ5IGVhc3kgd2l0aCBweXRob24= life is very easy with python
import base64
encoded = base64.b64encode('life is very easy with python')
print encoded
data = base64.b64decode(encoded)
print data
bGlmZSBpcyB2ZXJ5IGVhc3kgd2l0aCBweXRob24= life is very easy with python
from datetime import datetime import time date= datetime(2012,10,16) # You set date as datetime.now() print date print time.mktime(date.timetuple()) print datetime.fromtimestamp(time.mktime(date.timetuple()))
2012-10-16 00:00:00 1350324000.0 2012-10-16 00:00:00
class MyDecorator(object):
def __init__(self, f):
self.doSomethingCopy=f
print "This line will call on decoration"
def __call__(self,p,q): # here we pass the function parameter
print "This line will work when we call the function 'doSomething' "
self.doSomethingCopy(p+1,q+1)
@MyDecorator
def doSomething(a,b):
print "I am doing something"
print "A ",a," B ",b
doSomething(3,4)
This line will call on decoration This line will work when we call the function 'doSomething' I am doing something A 4 B 5
def show_chars(n):
list=['A','B','C','D','E','F','G','H','I','J']
for data, pos in zip(list, range(n)):
yield data
chars_set= show_chars(5)
for ch in chars_set:
print ch
A B C D E
a=[1,2,3] b=[4,5,6] z=zip(a,b) print z ai,bi=zip(*z) print ai print bi print "-"*25 a=[1,2] b=[4,5,6] z=zip(a,b) print z ai,bi=zip(*z) print ai print bi print "."*25 a=[1,2,4] b=[4,5] z=zip(a,b) print z ai,bi=zip(*z) print ai print bi
[(1, 4), (2, 5), (3, 6)] (1, 2, 3) (4, 5, 6) ------------------------- [(1, 4), (2, 5)] (1, 2) (4, 5) ......................... [(1, 4), (2, 5)] (1, 2) (4, 5)
def myFun(n):
for i in range(0,n):
yield i
it=myFun(5)
for i in it:
print i
0 1 2 3 4