= Python = Python is a programming language that lets you work more quickly and integrate your systems more effectively. Links: * [[http://docs.python.org/2/library/]] * [[http://www.tutorialspoint.com/python/]] == Time and date == {{{#!highlight python import time # get seconds since epoch until now in UTC to a string year-month-dayThour:minute:second strutc = time.strftime('%Y-%m-%dT%H:%M:%S', time.gmtime() ) # get seconds since epoch until now in localtime to a string year-month-dayThour:minute:second strlocal = time.strftime('%Y-%m-%dT%H:%M:%S', time.localtime() ) }}} == Write and reading data for a plist file == A plist file stores data in XML format. {{{#!highlight python import plistlib value = [{'key1':123,'key2':'asdf'},{'keyx1':'testing','keyz1':'yup'}] # save value in plist file plistlib.writePlist(value,'/tmp/plist1.plist') o=plistlib.readPlist('/tmp/plist1.plist') print o }}} Content of the file '''/tmp/plist1.plist''' {{{#!highlight xml key1 123 key2 asdf keyx1 testing keyz1 yup }}} == Threading == {{{#!highlight python #!/usr/bin/python # timestable.py # calculates the times table in concurrency import threading import time class TimesTable (threading.Thread): def __init__(self, timesTable): threading.Thread.__init__(self) #required self.timeTable = timesTable self.count = 1 def run(self): loop=True while loop: time.sleep(1) #sleep for 1 second result=self.timeTable * self.count print "%d*%d=%d"%(self.timeTable,self.count,result) if self.count<10: self.count = self.count+1 else: self.count=1 # create threads timesTable2 = TimesTable(2) timesTable5 = TimesTable(7) # start the threads timesTable2.start() timesTable5.start() }}}